/******************************************************************************* | |
* Copyright (c) 20017-2019 Cisco Systems, Inc. | |
* All rights reserved. This program and the accompanying materials | |
* are made available under the terms of the Eclipse Public License v1.0 | |
* which accompanies this distribution, and is available at | |
* http://www.eclipse.org/legal/epl-v10.html | |
* | |
*******************************************************************************/ | |
package org.eclipse.tigerstripe.workbench.ui.internal.preferences; | |
import java.util.stream.Stream; | |
import org.eclipse.core.runtime.preferences.ConfigurationScope; | |
import org.eclipse.jface.preference.BooleanFieldEditor; | |
import org.eclipse.jface.preference.FieldEditorPreferencePage; | |
import org.eclipse.jface.preference.IPreferenceStore; | |
import org.eclipse.swt.SWT; | |
import org.eclipse.swt.layout.GridData; | |
import org.eclipse.swt.widgets.Group; | |
import org.eclipse.tigerstripe.workbench.internal.BasePlugin; | |
import org.eclipse.tigerstripe.workbench.internal.builder.ArtifactAuditorFactory; | |
import org.eclipse.tigerstripe.workbench.ui.internal.dialogs.CustomStereotypeDialogFactory; | |
import org.eclipse.ui.IWorkbench; | |
import org.eclipse.ui.IWorkbenchPreferencePage; | |
import org.eclipse.ui.preferences.ScopedPreferenceStore; | |
public class ContributionsPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { | |
public static final String PAGE_ID = "org.eclipse.tigerstripe.ui.eclipse.preferences.ContributionsPreferencePage"; // $NON-NLS-1$ | |
public static final String P_USE_CUSTOM_STEROTYPE_DIALOG_FOR = "p.use_custom_stereotype_dialog_for_"; // $NON-NLS-1$ | |
public static final String P_USE_CUSTOM_DEPENDENCIES_DIALOG = "p.use_custom_dependencies_dialog"; // $NON-NLS-1$ | |
public ContributionsPreferencePage() { | |
super(GRID); | |
setPreferenceStore(new ScopedPreferenceStore(ConfigurationScope.INSTANCE, BasePlugin.PLUGIN_ID)); | |
setDescription("Preferences for Contributions"); | |
initializeDefaults(); | |
} | |
@Override | |
public void init(IWorkbench arg0) { | |
// N/A | |
} | |
@Override | |
protected void createFieldEditors() { | |
Group useGroup = new Group(getFieldEditorParent(), SWT.TITLE); | |
GridData gd = new GridData(GridData.FILL_HORIZONTAL); | |
gd.horizontalSpan = 2; | |
useGroup.setLayoutData(gd); | |
useGroup.setText("Use Custom Stereotype Dialogs"); | |
Stream.of(CustomStereotypeDialogFactory.list()).sorted((d1, d2) -> d1.compareTo(d2)).forEach(stereo -> addField( | |
new BooleanFieldEditor(P_USE_CUSTOM_STEROTYPE_DIALOG_FOR + stereo, stereo, useGroup))); | |
Group auditGroup = new Group(getFieldEditorParent(), SWT.TITLE); | |
gd.horizontalSpan = 2; | |
auditGroup.setLayoutData(gd); | |
auditGroup.setText("Use Custom Auditors"); | |
ArtifactAuditorFactory.INSTANCE.getAuditorMap().entrySet().stream() | |
.sorted((e1, e2) -> e1.getValue().getName().compareTo(e2.getValue().getName())) | |
.forEach(entry -> addField( | |
new BooleanFieldEditor(entry.getKey(), entry.getValue().getName(), auditGroup))); | |
Group dependenciesGroup = new Group(getFieldEditorParent(), SWT.TITLE); | |
dependenciesGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); | |
dependenciesGroup.setText("Use Custom Dependencies Editor"); | |
addField(new BooleanFieldEditor(P_USE_CUSTOM_DEPENDENCIES_DIALOG, "Use Custom Dependencies Editor", | |
dependenciesGroup)); | |
} | |
public static void initializeDefaults() { | |
IPreferenceStore store = new ScopedPreferenceStore(ConfigurationScope.INSTANCE, BasePlugin.PLUGIN_ID); | |
for (String stereo : CustomStereotypeDialogFactory.list()) { | |
store.setDefault(P_USE_CUSTOM_STEROTYPE_DIALOG_FOR + stereo, true); | |
} | |
store.setDefault(P_USE_CUSTOM_DEPENDENCIES_DIALOG, true); | |
} | |
} |