diff options
author | Eike Stepper | 2013-10-22 11:49:09 +0000 |
---|---|---|
committer | Eike Stepper | 2013-10-22 12:09:32 +0000 |
commit | 262e082974e7c6bb38d9ae9b61d7c6fa661802e4 (patch) | |
tree | 2ff0726f92272efa0c5e15334f142ed71410ccea | |
parent | 5290b3ccf59f15c6ee5147652cc9b26a1fe200be (diff) | |
download | cdo-262e082974e7c6bb38d9ae9b61d7c6fa661802e4.tar.gz cdo-262e082974e7c6bb38d9ae9b61d7c6fa661802e4.tar.xz cdo-262e082974e7c6bb38d9ae9b61d7c6fa661802e4.zip |
Add PreferencesRecorderAction
8 files changed, 253 insertions, 49 deletions
diff --git a/plugins/org.eclipse.emf.cdo.releng.preferences/src/org/eclipse/emf/cdo/releng/preferences/util/PreferencesUtil.java b/plugins/org.eclipse.emf.cdo.releng.preferences/src/org/eclipse/emf/cdo/releng/preferences/util/PreferencesUtil.java index f0b0510d4f..03f8b32b32 100644 --- a/plugins/org.eclipse.emf.cdo.releng.preferences/src/org/eclipse/emf/cdo/releng/preferences/util/PreferencesUtil.java +++ b/plugins/org.eclipse.emf.cdo.releng.preferences/src/org/eclipse/emf/cdo/releng/preferences/util/PreferencesUtil.java @@ -233,6 +233,22 @@ public final class PreferencesUtil return null; } + public static String getAbsolutePath(Property property) + { + return getAbsolutePath(property.getParent()) + "/" + property.getName(); + } + + public static String getAbsolutePath(PreferenceNode node) + { + PreferenceNode parent = node.getParent(); + if (parent == null) + { + return node.getName(); + } + + return getAbsolutePath(parent) + "/" + node.getName(); + } + public static IPath getLocation(Preferences preferences) { if (preferences == null) diff --git a/plugins/org.eclipse.emf.cdo.releng.setup.edit/src/org/eclipse/emf/cdo/releng/setup/provider/CompoundSetupTaskItemProvider.java b/plugins/org.eclipse.emf.cdo.releng.setup.edit/src/org/eclipse/emf/cdo/releng/setup/provider/CompoundSetupTaskItemProvider.java index 8d966cfcf1..1eefcd5ce7 100644 --- a/plugins/org.eclipse.emf.cdo.releng.setup.edit/src/org/eclipse/emf/cdo/releng/setup/provider/CompoundSetupTaskItemProvider.java +++ b/plugins/org.eclipse.emf.cdo.releng.setup.edit/src/org/eclipse/emf/cdo/releng/setup/provider/CompoundSetupTaskItemProvider.java @@ -134,14 +134,13 @@ public class CompoundSetupTaskItemProvider extends SetupTaskItemProvider impleme * This returns the label text for the adapted class. * <!-- begin-user-doc --> * <!-- end-user-doc --> - * @generated + * @generated NOT */ @Override public String getText(Object object) { String label = ((CompoundSetupTask)object).getName(); - return label == null || label.length() == 0 ? getString("_UI_CompoundSetupTask_type") - : getString("_UI_CompoundSetupTask_type") + " " + label; + return label == null || label.length() == 0 ? getString("_UI_CompoundSetupTask_type") : label; } /** diff --git a/plugins/org.eclipse.emf.cdo.releng.setup.edit/src/org/eclipse/emf/cdo/releng/setup/provider/EclipsePreferenceTaskItemProvider.java b/plugins/org.eclipse.emf.cdo.releng.setup.edit/src/org/eclipse/emf/cdo/releng/setup/provider/EclipsePreferenceTaskItemProvider.java index c7a1dd2dd7..39f56c8065 100644 --- a/plugins/org.eclipse.emf.cdo.releng.setup.edit/src/org/eclipse/emf/cdo/releng/setup/provider/EclipsePreferenceTaskItemProvider.java +++ b/plugins/org.eclipse.emf.cdo.releng.setup.edit/src/org/eclipse/emf/cdo/releng/setup/provider/EclipsePreferenceTaskItemProvider.java @@ -136,7 +136,13 @@ public class EclipsePreferenceTaskItemProvider extends SetupTaskItemProvider imp return getString("_UI_EclipsePreferenceTask_type"); } - return "" + key + " = " + value; + String label = "" + key; + if (value != null) + { + label += " = " + value; + } + + return label; } /** diff --git a/plugins/org.eclipse.emf.cdo.releng.setup.editor/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.releng.setup.editor/META-INF/MANIFEST.MF index ec19bc4e47..cba03cec1f 100644 --- a/plugins/org.eclipse.emf.cdo.releng.setup.editor/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.emf.cdo.releng.setup.editor/META-INF/MANIFEST.MF @@ -15,6 +15,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)", org.eclipse.emf.cdo.releng.setup.edit;visibility:=reexport;bundle-version="[1.0.0,2.0.0)", org.eclipse.emf.cdo.releng.workingsets.edit;visibility:=reexport;bundle-version="[1.0.0,2.0.0)", org.eclipse.emf.cdo.releng.predicates.edit;visibility:=reexport;bundle-version="[1.0.0,2.0.0)", + org.eclipse.emf.cdo.releng.preferences;bundle-version="[1.0.0,2.0.0)", org.eclipse.emf.ecore.xmi;visibility:=reexport;bundle-version="[2.5.0,3.0.0)", org.eclipse.emf.edit.ui;visibility:=reexport;bundle-version="[2.5.0,3.0.0)", org.eclipse.ui.ide;visibility:=reexport;bundle-version="[3.5.0,4.0.0)", diff --git a/plugins/org.eclipse.emf.cdo.releng.setup.editor/src/org/eclipse/emf/cdo/releng/setup/presentation/SetupActionBarContributor.java b/plugins/org.eclipse.emf.cdo.releng.setup.editor/src/org/eclipse/emf/cdo/releng/setup/presentation/SetupActionBarContributor.java index ef1f7fc4b8..a4fa357362 100644 --- a/plugins/org.eclipse.emf.cdo.releng.setup.editor/src/org/eclipse/emf/cdo/releng/setup/presentation/SetupActionBarContributor.java +++ b/plugins/org.eclipse.emf.cdo.releng.setup.editor/src/org/eclipse/emf/cdo/releng/setup/presentation/SetupActionBarContributor.java @@ -10,7 +10,24 @@ */ package org.eclipse.emf.cdo.releng.setup.presentation; +import org.eclipse.emf.cdo.releng.internal.setup.Activator; +import org.eclipse.emf.cdo.releng.preferences.PreferenceNode; +import org.eclipse.emf.cdo.releng.preferences.PreferencesPackage; +import org.eclipse.emf.cdo.releng.preferences.Property; +import org.eclipse.emf.cdo.releng.preferences.util.PreferencesUtil; +import org.eclipse.emf.cdo.releng.setup.EclipsePreferenceTask; +import org.eclipse.emf.cdo.releng.setup.SetupFactory; +import org.eclipse.emf.cdo.releng.setup.SetupTask; +import org.eclipse.emf.cdo.releng.setup.SetupTaskContainer; + +import org.eclipse.emf.common.command.CommandStack; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.ui.viewer.IViewerProvider; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.util.EContentAdapter; +import org.eclipse.emf.edit.command.ChangeCommand; +import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; import org.eclipse.emf.edit.domain.EditingDomain; import org.eclipse.emf.edit.domain.IEditingDomainProvider; import org.eclipse.emf.edit.ui.action.ControlAction; @@ -31,17 +48,22 @@ import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.action.SubContributionItem; +import org.eclipse.jface.preference.PreferenceDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.PartInitException; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; /** * This is the action bar contributor for the Setup model editor. @@ -154,6 +176,8 @@ public class SetupActionBarContributor extends EditingDomainActionBarContributor */ protected IMenuManager createSiblingMenuManager; + private PreferenceRecorderAction recordPreferencesAction = new PreferenceRecorderAction(); + /** * This creates an instance of the contributor. * <!-- begin-user-doc --> @@ -172,12 +196,13 @@ public class SetupActionBarContributor extends EditingDomainActionBarContributor * This adds Separators for editor additions to the tool bar. * <!-- begin-user-doc --> * <!-- end-user-doc --> - * @generated + * @generated NOT */ @Override public void contributeToToolBar(IToolBarManager toolBarManager) { toolBarManager.add(new Separator("setup-settings")); + toolBarManager.add(recordPreferencesAction); toolBarManager.add(new Separator("setup-additions")); } @@ -268,7 +293,7 @@ public class SetupActionBarContributor extends EditingDomainActionBarContributor * <!-- end-user-doc --> * @generated */ - public void selectionChanged(SelectionChangedEvent event) + public void selectionChangedGen(SelectionChangedEvent event) { // Remove any menu items for old selection. // @@ -314,6 +339,12 @@ public class SetupActionBarContributor extends EditingDomainActionBarContributor } } + public void selectionChanged(SelectionChangedEvent event) + { + selectionChangedGen(event); + recordPreferencesAction.selectionChanged(event); + } + /** * This generates a {@link org.eclipse.emf.edit.ui.action.CreateChildAction} for each object in <code>descriptors</code>, * and returns the collection of these actions. @@ -469,4 +500,169 @@ public class SetupActionBarContributor extends EditingDomainActionBarContributor return true; } + /** + * @author Eike Stepper + */ + private class PreferenceRecorderAction extends Action + { + private SetupTaskContainer container; + + private PreferenceNode rootPreferenceNode; + + private EContentAdapter preferenceAdapter; + + public PreferenceRecorderAction() + { + super("Record", AS_CHECK_BOX); + setImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/recorder.gif")); + setToolTipText("Record preference changes into the selected setup task container"); + } + + public void selectionChanged(SelectionChangedEvent event) + { + if (!isChecked()) + { + ISelection selection = event.getSelection(); + if (selection instanceof IStructuredSelection) + { + IStructuredSelection structuredSelection = (IStructuredSelection)selection; + if (structuredSelection.size() == 1) + { + Object element = structuredSelection.getFirstElement(); + if (element instanceof SetupTaskContainer) + { + container = (SetupTaskContainer)element; + setEnabled(true); + return; + } + } + } + + container = null; + setEnabled(false); + } + } + + @Override + public void run() + { + if (isChecked()) + { + if (activeEditorPart instanceof IViewerProvider) + { + Viewer viewer = ((IViewerProvider)activeEditorPart).getViewer(); + if (viewer instanceof TreeViewer) + { + ((TreeViewer)viewer).setExpandedState(container, true); + } + } + + preferenceAdapter = createPreferenceAdapter(); + rootPreferenceNode = PreferencesUtil.getRootPreferenceNode(true); + rootPreferenceNode.eAdapters().add(preferenceAdapter); + + ChangeCommand command = new ChangeCommand(container) + { + @Override + protected void doExecute() + { + PreferenceDialog dialog = org.eclipse.ui.dialogs.PreferencesUtil.createPreferenceDialogOn(null, null, null, + null); + dialog.open(); + } + }; + + EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(container); + CommandStack commandStack = editingDomain.getCommandStack(); + commandStack.execute(command); + + rootPreferenceNode.eAdapters().remove(preferenceAdapter); + rootPreferenceNode = null; + preferenceAdapter = null; + setChecked(false); + } + } + + private EContentAdapter createPreferenceAdapter() + { + return new EContentAdapter() + { + private Map<Property, String> map = new HashMap<Property, String>(); + + @Override + protected void setTarget(EObject target) + { + super.setTarget(target); + if (target instanceof Property) + { + Property property = (Property)target; + String absolutePath = PreferencesUtil.getAbsolutePath(property); + if (absolutePath.startsWith("/instance/")) + { + map.put(property, absolutePath); + } + } + } + + @Override + public void notifyChanged(Notification notification) + { + super.notifyChanged(notification); + switch (notification.getEventType()) + { + case Notification.SET: + if (notification.getFeature() == PreferencesPackage.Literals.PROPERTY__VALUE) + { + Property property = (Property)notification.getNotifier(); + setPreference(property, property.getValue()); + } + break; + + case Notification.ADD: + if (notification.getFeature() == PreferencesPackage.Literals.PREFERENCE_NODE__PROPERTIES) + { + Property property = (Property)notification.getNewValue(); + setPreference(property, property.getValue()); + } + break; + + case Notification.REMOVE: + if (notification.getFeature() == PreferencesPackage.Literals.PREFERENCE_NODE__PROPERTIES) + { + Property property = (Property)notification.getOldValue(); + setPreference(property, null); + } + break; + } + } + + private void setPreference(Property property, String value) + { + String absolutePath = map.get(property); + if (absolutePath != null) + { + EList<SetupTask> setupTasks = container.getSetupTasks(); + for (Iterator<SetupTask> it = setupTasks.iterator(); it.hasNext();) + { + SetupTask setupTask = it.next(); + if (setupTask instanceof EclipsePreferenceTask) + { + EclipsePreferenceTask preferenceTask = (EclipsePreferenceTask)setupTask; + if (absolutePath.equals(preferenceTask.getKey())) + { + it.remove(); + } + } + } + + EclipsePreferenceTask task = SetupFactory.eINSTANCE.createEclipsePreferenceTask(); + task.setKey(absolutePath); + task.setValue(value); + + setupTasks.add(task); + } + } + }; + } + } } diff --git a/plugins/org.eclipse.emf.cdo.releng.setup/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.releng.setup/META-INF/MANIFEST.MF index c8145eee02..b1722d1fc2 100644 --- a/plugins/org.eclipse.emf.cdo.releng.setup/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.emf.cdo.releng.setup/META-INF/MANIFEST.MF @@ -8,33 +8,33 @@ Bundle-Vendor: %providerName Bundle-Localization: plugin Require-Bundle: org.eclipse.net4j.util;bundle-version="[3.0.0,4.0.0)", org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)", - org.eclipse.emf.cdo.releng.workingsets;visibility:=reexport;bundle-version="[1.0.0,2.0.0)", - org.eclipse.emf.cdo.releng.predicates;visibility:=reexport;bundle-version="[1.0.0,2.0.0)", - org.eclipse.emf.ecore;visibility:=reexport;bundle-version="[2.5.0,3.0.0)", + org.eclipse.emf.cdo.releng.workingsets;bundle-version="[1.0.0,2.0.0)";visibility:=reexport, + org.eclipse.emf.cdo.releng.predicates;bundle-version="[1.0.0,2.0.0)";visibility:=reexport, + org.eclipse.emf.ecore;bundle-version="[2.5.0,3.0.0)";visibility:=reexport, org.eclipse.emf.ecore.xmi;bundle-version="[2.5.0,3.0.0)", - org.eclipse.core.resources;resolution:=optional;bundle-version="[3.5.0,4.0.0)", - org.eclipse.core.variables;resolution:=optional;bundle-version="[3.0.0,4.0.0)", - org.eclipse.pde.core;resolution:=optional;bundle-version="[3.5.0,4.0.0)", - org.eclipse.pde.api.tools;resolution:=optional;bundle-version="[1.0.0,2.0.0)", - org.eclipse.team.ui;resolution:=optional;bundle-version="[3.5.0,4.0.0)", - javaewah;resolution:=optional;bundle-version="[0.0.0,1.0.0)", - org.eclipse.jgit;resolution:=optional;bundle-version="[3.0.0,4.0.0)", - org.eclipse.egit;resolution:=optional;bundle-version="[3.0.0,4.0.0)", - org.eclipse.egit.core;resolution:=optional;bundle-version="[3.0.0,4.0.0)", - org.eclipse.egit.ui;resolution:=optional;bundle-version="[3.0.0,4.0.0)", - org.eclipse.emf.edit.ui;resolution:=optional;bundle-version="[2.5.0,3.0.0)", - org.eclipse.ecf.provider.filetransfer;resolution:=optional;bundle-version="[3.2.0,4.0.0)", - org.eclipse.ecf.filetransfer;resolution:=optional;bundle-version="[5.0.0,6.0.0)", - org.eclipse.ecf.identity;resolution:=optional;bundle-version="[3.2.0,4.0.0)", - org.eclipse.ecf;resolution:=optional;bundle-version="[3.2.0,4.0.0)", - org.eclipse.buckminster.sax;resolution:=optional;bundle-version="[1.0.0,2.0.0)", - org.eclipse.buckminster.cmdline;resolution:=optional;bundle-version="[1.0.0,2.0.0)", - org.eclipse.buckminster.download;resolution:=optional;bundle-version="[1.0.0,2.0.0)", - org.eclipse.buckminster.runtime;resolution:=optional;bundle-version="[1.0.0,2.0.0)", - org.eclipse.buckminster.core;resolution:=optional;bundle-version="[1.0.0,2.0.0)", - org.eclipse.buckminster.pde;resolution:=optional;bundle-version="[1.0.0,2.0.0)", + org.eclipse.core.resources;bundle-version="[3.5.0,4.0.0)";resolution:=optional, + org.eclipse.core.variables;bundle-version="[3.0.0,4.0.0)";resolution:=optional, + org.eclipse.pde.core;bundle-version="[3.5.0,4.0.0)";resolution:=optional, + org.eclipse.pde.api.tools;bundle-version="[1.0.0,2.0.0)";resolution:=optional, + org.eclipse.team.ui;bundle-version="[3.5.0,4.0.0)";resolution:=optional, + javaewah;bundle-version="[0.0.0,1.0.0)";resolution:=optional, + org.eclipse.jgit;bundle-version="[3.0.0,4.0.0)";resolution:=optional, + org.eclipse.egit;bundle-version="[3.0.0,4.0.0)";resolution:=optional, + org.eclipse.egit.core;bundle-version="[3.0.0,4.0.0)";resolution:=optional, + org.eclipse.egit.ui;bundle-version="[3.0.0,4.0.0)";resolution:=optional, + org.eclipse.emf.edit.ui;bundle-version="[2.5.0,3.0.0)";resolution:=optional, + org.eclipse.ecf.provider.filetransfer;bundle-version="[3.2.0,4.0.0)";resolution:=optional, + org.eclipse.ecf.filetransfer;bundle-version="[5.0.0,6.0.0)";resolution:=optional, + org.eclipse.ecf.identity;bundle-version="[3.2.0,4.0.0)";resolution:=optional, + org.eclipse.ecf;bundle-version="[3.2.0,4.0.0)";resolution:=optional, + org.eclipse.buckminster.sax;bundle-version="[1.0.0,2.0.0)";resolution:=optional, + org.eclipse.buckminster.cmdline;bundle-version="[1.0.0,2.0.0)";resolution:=optional, + org.eclipse.buckminster.download;bundle-version="[1.0.0,2.0.0)";resolution:=optional, + org.eclipse.buckminster.runtime;bundle-version="[1.0.0,2.0.0)";resolution:=optional, + org.eclipse.buckminster.core;bundle-version="[1.0.0,2.0.0)";resolution:=optional, + org.eclipse.buckminster.pde;bundle-version="[1.0.0,2.0.0)";resolution:=optional, org.eclipse.equinox.p2.core;bundle-version="[2.0.0,3.0.0)", - org.eclipse.equinox.p2.ui;resolution:=optional;bundle-version="[2.0.0,3.0.0)", + org.eclipse.equinox.p2.ui;bundle-version="[2.0.0,3.0.0)";resolution:=optional, org.eclipse.equinox.p2.metadata;bundle-version="[2.0.0,3.0.0)", org.eclipse.equinox.p2.repository;bundle-version="[2.0.0,3.0.0)", org.eclipse.equinox.p2.artifact.repository;bundle-version="[1.0.0,2.0.0)", diff --git a/plugins/org.eclipse.emf.cdo.releng.setup/icons/recorder.gif b/plugins/org.eclipse.emf.cdo.releng.setup/icons/recorder.gif Binary files differnew file mode 100644 index 0000000000..5a90d9db24 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.releng.setup/icons/recorder.gif diff --git a/plugins/org.eclipse.emf.cdo.releng.setup/src/org/eclipse/emf/cdo/releng/internal/setup/Activator.java b/plugins/org.eclipse.emf.cdo.releng.setup/src/org/eclipse/emf/cdo/releng/internal/setup/Activator.java index 5bcf7a3b8b..b4390510d1 100644 --- a/plugins/org.eclipse.emf.cdo.releng.setup/src/org/eclipse/emf/cdo/releng/internal/setup/Activator.java +++ b/plugins/org.eclipse.emf.cdo.releng.setup/src/org/eclipse/emf/cdo/releng/internal/setup/Activator.java @@ -12,16 +12,16 @@ package org.eclipse.emf.cdo.releng.internal.setup; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Status; import org.eclipse.ui.IStartup; +import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; /** * @author Eike Stepper */ -public class Activator extends Plugin +public class Activator extends AbstractUIPlugin { public static final String PLUGIN_ID = "org.eclipse.emf.cdo.releng.setup"; @@ -32,8 +32,6 @@ public class Activator extends Plugin private static BundleContext bundleContext; - private SetupTaskPerformer setupTaskPerformer; - public Activator() { } @@ -49,8 +47,9 @@ public class Activator extends Plugin { if (SETUP_IDE) { - setupTaskPerformer = new SetupTaskPerformer(false); + SetupTaskPerformer setupTaskPerformer = new SetupTaskPerformer(false); setupTaskPerformer.perform(); + setupTaskPerformer.dispose(); } } catch (Exception ex) @@ -62,19 +61,6 @@ public class Activator extends Plugin @Override public void stop(BundleContext context) throws Exception { - try - { - if (setupTaskPerformer != null) - { - setupTaskPerformer.dispose(); - setupTaskPerformer = null; - } - } - catch (Exception ex) - { - log(ex); - } - plugin = null; super.stop(context); } |