diff options
author | Eike Stepper | 2013-10-23 06:45:47 +0000 |
---|---|---|
committer | Eike Stepper | 2013-10-23 06:45:47 +0000 |
commit | 549c81a7bf52716c942997b142bfeca3be77fff2 (patch) | |
tree | d8145b659829c1b34d7dea75ab8777fdc774ad67 | |
parent | a5812d0e980e98ac98c0b1b5d3bbe42c5387a370 (diff) | |
download | cdo-549c81a7bf52716c942997b142bfeca3be77fff2.tar.gz cdo-549c81a7bf52716c942997b142bfeca3be77fff2.tar.xz cdo-549c81a7bf52716c942997b142bfeca3be77fff2.zip |
Add PreferencesRecorderAction
4 files changed, 98 insertions, 64 deletions
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 5af9f3f5c8..f5a80ef593 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 @@ -15,6 +15,7 @@ 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.CompoundSetupTask; import org.eclipse.emf.cdo.releng.setup.EclipsePreferenceTask; import org.eclipse.emf.cdo.releng.setup.SetupFactory; import org.eclipse.emf.cdo.releng.setup.SetupTask; @@ -24,6 +25,7 @@ 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.common.util.TreeIterator; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.util.EContentAdapter; import org.eclipse.emf.edit.command.ChangeCommand; @@ -37,6 +39,7 @@ import org.eclipse.emf.edit.ui.action.EditingDomainActionBarContributor; import org.eclipse.emf.edit.ui.action.LoadResourceAction; import org.eclipse.emf.edit.ui.action.ValidateAction; +import org.eclipse.core.runtime.Path; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.ActionContributionItem; import org.eclipse.jface.action.IAction; @@ -529,11 +532,14 @@ public class SetupActionBarContributor extends EditingDomainActionBarContributor if (structuredSelection.size() == 1) { Object element = structuredSelection.getFirstElement(); - if (element instanceof SetupTaskContainer) + if (element instanceof EObject) { - container = (SetupTaskContainer)element; - setEnabled(true); - return; + container = getSetupTaskContainer((EObject)element); + if (container != null) + { + setEnabled(true); + return; + } } } } @@ -548,20 +554,13 @@ public class SetupActionBarContributor extends EditingDomainActionBarContributor { if (isChecked()) { - if (activeEditorPart instanceof IViewerProvider) - { - Viewer viewer = ((IViewerProvider)activeEditorPart).getViewer(); - if (viewer instanceof TreeViewer) - { - ((TreeViewer)viewer).setExpandedState(container, true); - } - } + expandItem(container); preferenceAdapter = createPreferenceAdapter(); rootPreferenceNode = PreferencesUtil.getRootPreferenceNode(true); rootPreferenceNode.eAdapters().add(preferenceAdapter); - ChangeCommand command = new ChangeCommand(container) + ChangeCommand command = new ChangeCommand(container.eResource()) { @Override protected void doExecute() @@ -583,11 +582,88 @@ public class SetupActionBarContributor extends EditingDomainActionBarContributor } } + protected void updatePreference(String key, String value) + { + for (TreeIterator<EObject> it = container.eResource().getAllContents(); it.hasNext();) + { + EObject object = it.next(); + if (object instanceof EclipsePreferenceTask) + { + EclipsePreferenceTask preferenceTask = (EclipsePreferenceTask)object; + if (key.equals(preferenceTask.getKey())) + { + preferenceTask.setValue(value); + expandItem(preferenceTask.eContainer()); + return; + } + } + } + + EclipsePreferenceTask task = SetupFactory.eINSTANCE.createEclipsePreferenceTask(); + task.setKey(key); + task.setValue(value); + + String pluginID = new Path(key).segment(1).toString(); + CompoundSetupTask compoundTask = getCompoundTask(pluginID); + compoundTask.getSetupTasks().add(task); + expandItem(compoundTask); + } + + private void expandItem(final EObject object) + { + if (activeEditorPart instanceof IViewerProvider) + { + activeEditor.getSite().getShell().getDisplay().asyncExec(new Runnable() + { + public void run() + { + Viewer viewer = ((IViewerProvider)activeEditorPart).getViewer(); + if (viewer instanceof TreeViewer) + { + ((TreeViewer)viewer).setExpandedState(object, true); + } + } + }); + } + } + + private CompoundSetupTask getCompoundTask(String pluginID) + { + EList<SetupTask> setupTasks = container.getSetupTasks(); + for (Iterator<SetupTask> it = setupTasks.iterator(); it.hasNext();) + { + SetupTask setupTask = it.next(); + if (setupTask instanceof CompoundSetupTask) + { + CompoundSetupTask compoundTask = (CompoundSetupTask)setupTask; + if (pluginID.equals(compoundTask.getName())) + { + return compoundTask; + } + } + } + + CompoundSetupTask compoundTask = SetupFactory.eINSTANCE.createCompoundSetupTask(); + compoundTask.setName(pluginID); + setupTasks.add(compoundTask); + return compoundTask; + } + + private SetupTaskContainer getSetupTaskContainer(EObject object) + { + while (object != null && !(object instanceof SetupTaskContainer)) + { + object = object.eContainer(); + } + + return (SetupTaskContainer)object; + } + private EContentAdapter createPreferenceAdapter() { return new EContentAdapter() { - private Map<Property, String> map = new HashMap<Property, String>(); + private Map<Property, String> paths = new HashMap<Property, String>(); @Override protected void setTarget(EObject target) @@ -599,7 +675,7 @@ public class SetupActionBarContributor extends EditingDomainActionBarContributor String absolutePath = property.getAbsolutePath(); if (absolutePath.startsWith("/instance/")) { - map.put(property, absolutePath); + paths.put(property, absolutePath); } } } @@ -614,7 +690,7 @@ public class SetupActionBarContributor extends EditingDomainActionBarContributor if (notification.getFeature() == PreferencesPackage.Literals.PROPERTY__VALUE) { Property property = (Property)notification.getNotifier(); - setPreference(property, property.getValue()); + notifyChanged(property, property.getValue()); } break; @@ -622,7 +698,7 @@ public class SetupActionBarContributor extends EditingDomainActionBarContributor if (notification.getFeature() == PreferencesPackage.Literals.PREFERENCE_NODE__PROPERTIES) { Property property = (Property)notification.getNewValue(); - setPreference(property, property.getValue()); + notifyChanged(property, property.getValue()); } break; @@ -630,36 +706,18 @@ public class SetupActionBarContributor extends EditingDomainActionBarContributor if (notification.getFeature() == PreferencesPackage.Literals.PREFERENCE_NODE__PROPERTIES) { Property property = (Property)notification.getOldValue(); - setPreference(property, null); + notifyChanged(property, null); } break; } } - private void setPreference(Property property, String value) + private void notifyChanged(Property property, String value) { - String absolutePath = map.get(property); + String absolutePath = paths.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); + updatePreference(absolutePath, value); } } }; 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 b4390510d1..b4660937e4 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 @@ -49,7 +49,6 @@ public class Activator extends AbstractUIPlugin { SetupTaskPerformer setupTaskPerformer = new SetupTaskPerformer(false); setupTaskPerformer.perform(); - setupTaskPerformer.dispose(); } } catch (Exception ex) diff --git a/plugins/org.eclipse.emf.cdo.releng.setup/src/org/eclipse/emf/cdo/releng/internal/setup/SetupTaskPerformer.java b/plugins/org.eclipse.emf.cdo.releng.setup/src/org/eclipse/emf/cdo/releng/internal/setup/SetupTaskPerformer.java index f754780968..bc639dece5 100644 --- a/plugins/org.eclipse.emf.cdo.releng.setup/src/org/eclipse/emf/cdo/releng/internal/setup/SetupTaskPerformer.java +++ b/plugins/org.eclipse.emf.cdo.releng.setup/src/org/eclipse/emf/cdo/releng/internal/setup/SetupTaskPerformer.java @@ -4,7 +4,7 @@ * 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 - * + * * Contributors: * Eike Stepper - initial API and implementation */ @@ -109,12 +109,6 @@ public class SetupTaskPerformer extends HashMap<Object, Object> implements Setup initialize(); } - public void dispose() - { - setup = null; - branchDir = null; - } - public void log(String line) { if (progress != null) diff --git a/plugins/org.eclipse.emf.cdo.releng.ui/src/org/eclipse/emf/cdo/releng/ui/Activator.java b/plugins/org.eclipse.emf.cdo.releng.ui/src/org/eclipse/emf/cdo/releng/ui/Activator.java index f8687837ae..4ee0094128 100644 --- a/plugins/org.eclipse.emf.cdo.releng.ui/src/org/eclipse/emf/cdo/releng/ui/Activator.java +++ b/plugins/org.eclipse.emf.cdo.releng.ui/src/org/eclipse/emf/cdo/releng/ui/Activator.java @@ -13,7 +13,6 @@ package org.eclipse.emf.cdo.releng.ui; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -import org.eclipse.swt.graphics.Image; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; @@ -23,12 +22,6 @@ import org.osgi.framework.BundleContext; */ public class Activator extends AbstractUIPlugin { - public static final String CORRECTION_DELETE_GIF = "icons/correction_delete.gif"; - - public static final String CORRECTION_CHANGE_GIF = "icons/correction_change.gif"; - - public static final String CORRECTION_CONFIGURE_GIF = "icons/correction_configure.gif"; - public static final String PLUGIN_ID = "org.eclipse.emf.cdo.releng.ui"; private static Activator plugin; @@ -47,16 +40,6 @@ public class Activator extends AbstractUIPlugin { super.start(context); plugin = this; - - registerImage(CORRECTION_CHANGE_GIF); - registerImage(CORRECTION_DELETE_GIF); - registerImage(CORRECTION_CONFIGURE_GIF); - } - - private void registerImage(String key) - { - Image image = imageDescriptorFromPlugin(PLUGIN_ID, key).createImage(); - getImageRegistry().put(key, image); } @Override |