Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrschnekenbu2014-04-29 12:13:33 +0000
committerrschnekenbu2014-04-30 16:51:23 +0000
commitff692dc326fab14140640a299b10c1588d6b74ff (patch)
tree5839ae3f4f4d211058dd6a2de39e7709a05056e4 /plugins/customization
parentc5f58ef502b9c04531637b048fb1b830997116cf (diff)
downloadorg.eclipse.papyrus-ff692dc326fab14140640a299b10c1588d6b74ff.tar.gz
org.eclipse.papyrus-ff692dc326fab14140640a299b10c1588d6b74ff.tar.xz
org.eclipse.papyrus-ff692dc326fab14140640a299b10c1588d6b74ff.zip
424431: [Core] Deployment of Palettes should be possible at runtime
https://bugs.eclipse.org/bugs/show_bug.cgi?id=424431 - first implementation of the deploy/undeploy palette for palette configuration (model based configuration) - small refactoring for the papyrus palette preferences (to support model -based palette configuration deployment) - API break: the ExtendedPluginPaletteProvider is not longer in plugin oep.uml.diagram.paletteconfiguraiton, but in uml.diagram.common (the dependency has been changed for these 2 plugins, common now depends of the palette configuration) Conflicts: plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.paletteconfiguration/META-INF/MANIFEST.MF Change-Id: I7f7e6ad90c831d1d483f24119bcb688dfdbbc313 Signed-off-by: rschnekenbu <remi.schnekenburger@cea.fr>
Diffstat (limited to 'plugins/customization')
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.palette/plugin.xml58
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/ExtendedPaletteContentPage.java15
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/LocalPaletteInformationPage.java7
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/AbstractDeployPaletteConfigurationHandler.java369
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/AbstractUndeployPaletteConfigurationHandler.java136
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/DeployExtendedPaletteConfigurationHandler.java58
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/DeployPaletteConfigurationHandler.java294
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/UndeployExtendedPaletteConfigurationHandler.java44
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/UndeployPaletteConfigurationHandler.java96
9 files changed, 714 insertions, 363 deletions
diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/plugin.xml b/plugins/customization/org.eclipse.papyrus.customization.palette/plugin.xml
index 2857c76fa0b..db6c9b24fb3 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.palette/plugin.xml
+++ b/plugins/customization/org.eclipse.papyrus.customization.palette/plugin.xml
@@ -60,6 +60,54 @@
</with>
</visibleWhen>
</command>
+ <command
+ commandId="org.eclipse.papyrus.customization.palette.extended.undeploy"
+ icon="icons/configuration.gif"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <iterate
+ ifEmpty="false"
+ operator="and">
+ <adapt
+ type="org.eclipse.core.resources.IFile">
+ <or>
+ <test
+ property="org.eclipse.core.resources.extension"
+ value="paletteconfiguration">
+ </test>
+ </or>
+ </adapt>
+ </iterate>
+ </with>
+ </visibleWhen>
+ </command>
+ <command
+ commandId="org.eclipse.papyrus.customization.palette.extended.deploy"
+ icon="icons/configuration.gif"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <iterate
+ ifEmpty="false"
+ operator="and">
+ <adapt
+ type="org.eclipse.core.resources.IFile">
+ <or>
+ <test
+ property="org.eclipse.core.resources.extension"
+ value="paletteconfiguration">
+ </test>
+ </or>
+ </adapt>
+ </iterate>
+ </with>
+ </visibleWhen>
+ </command>
</menuContribution>
</extension>
<extension
@@ -74,5 +122,15 @@
id="org.eclipse.papyrus.customization.palette.undeploy"
name="Disable Palette configuration">
</command>
+ <command
+ defaultHandler="org.eclipse.papyrus.customization.palette.handler.DeployExtendedPaletteConfigurationHandler"
+ id="org.eclipse.papyrus.customization.palette.extended.deploy"
+ name="Deploy Extended Palette configuration">
+ </command>
+ <command
+ defaultHandler="org.eclipse.papyrus.customization.palette.handler.UndeployExtendedPaletteConfigurationHandler"
+ id="org.eclipse.papyrus.customization.palette.extended.undeploy"
+ name="Disable Extended Palette configuration">
+ </command>
</extension>
</plugin>
diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/ExtendedPaletteContentPage.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/ExtendedPaletteContentPage.java
index 6f7cafe77a2..0e92dcaa6e6 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/ExtendedPaletteContentPage.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/ExtendedPaletteContentPage.java
@@ -20,6 +20,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.eclipse.core.runtime.IAdaptable;
@@ -75,6 +76,7 @@ import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil;
import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPalettePreferences;
import org.eclipse.papyrus.uml.diagram.common.service.AspectCreationEntry;
import org.eclipse.papyrus.uml.diagram.common.service.IPapyrusPaletteConstant;
+import org.eclipse.papyrus.uml.diagram.common.service.PaletteConfigurationUtils;
import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService;
import org.eclipse.papyrus.uml.diagram.common.service.palette.StereotypeAspectActionProvider;
import org.eclipse.papyrus.uml.diagram.paletteconfiguration.Configuration;
@@ -85,7 +87,6 @@ import org.eclipse.papyrus.uml.diagram.paletteconfiguration.Paletteconfiguration
import org.eclipse.papyrus.uml.diagram.paletteconfiguration.SeparatorConfiguration;
import org.eclipse.papyrus.uml.diagram.paletteconfiguration.StackConfiguration;
import org.eclipse.papyrus.uml.diagram.paletteconfiguration.ToolConfiguration;
-import org.eclipse.papyrus.uml.diagram.paletteconfiguration.util.PaletteConfigurationUtils;
import org.eclipse.papyrus.uml.diagram.paletteconfiguration.util.PaletteconfigurationSwitch;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
@@ -838,7 +839,7 @@ public class ExtendedPaletteContentPage extends WizardPage implements Listener {
return;
}
- Iterator<Object> it = selection.iterator();
+ Iterator<?> it = selection.iterator();
while(it.hasNext()) {
Object o = it.next();
if(o instanceof IAdaptable) {
@@ -1342,7 +1343,7 @@ public class ExtendedPaletteContentPage extends WizardPage implements Listener {
if(topPackage != null) {
return topPackage.getAllAppliedProfiles();
}
- return Collections.EMPTY_LIST;
+ return Collections.emptyList();
}
/**
@@ -2122,12 +2123,12 @@ public class ExtendedPaletteContentPage extends WizardPage implements Listener {
List<Class> metaclasses = stereotype.getAllExtendedMetaclasses();
for(Class stMetaclass : metaclasses) {
// get Eclass
- java.lang.Class metaclassClass = stMetaclass.getClass();
+ java.lang.Class<?> metaclassClass = stMetaclass.getClass();
if(metaclassClass != null) {
EClassifier metaClassifier = UMLPackage.eINSTANCE.getEClassifier(stMetaclass.getName());
if(((EClass)metaClassifier).isSuperTypeOf(toolMetaclass)) {
// should create the palette entry
- HashMap properties = new HashMap();
+ Map<Object, Object> properties = new HashMap<Object, Object>();
properties.put(IPapyrusPaletteConstant.ASPECT_ACTION_KEY, StereotypeAspectActionProvider.createConfigurationNode(stereotype.getQualifiedName()));
AspectCreationEntry aspectEntry = new AspectCreationEntry(stereotype.getName() + " (" + entry.getLabel() + ")", "Create an element with a stereotype", entry.getId() + "_" + System.currentTimeMillis(), entry.getSmallIcon(), (CombinedTemplateCreationEntry)entry, properties);
entries.add(aspectEntry);
@@ -2241,8 +2242,8 @@ public class ExtendedPaletteContentPage extends WizardPage implements Listener {
EClassifier metaClassifier = UMLPackage.eINSTANCE.getEClassifier(stMetaclass.getName());
if(((EClass)metaClassifier).isSuperTypeOf(toolMetaclass)) {
// should create the palette entry
- HashMap properties = new HashMap();
- ArrayList<String> stereotypesQNToApply = new ArrayList<String>();
+ Map<Object, Object> properties = new HashMap<Object, Object>();
+ // ArrayList<String> stereotypesQNToApply = new ArrayList<String>();
properties.put(IPapyrusPaletteConstant.ASPECT_ACTION_KEY, StereotypeAspectActionProvider.createConfigurationNode(stereotype.getQualifiedName()));
AspectCreationEntry aspectEntry = new AspectCreationEntry(stereotype.getName() + " (" + entry.getLabel() + ")", "Create an element with a stereotype", entry.getId() + "_" + System.currentTimeMillis(), entry.getSmallIcon(), entry, properties);
entries.add(aspectEntry);
diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/LocalPaletteInformationPage.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/LocalPaletteInformationPage.java
index 03bae76048d..552193087d5 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/LocalPaletteInformationPage.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/LocalPaletteInformationPage.java
@@ -229,7 +229,12 @@ public class LocalPaletteInformationPage extends WizardPage implements Listener
* value to set
*/
protected void initPriority(ProviderPriority value) {
- this.priority = value; // by default, Medium
+ if(value!=null) {
+ this.priority = value;
+ } else {
+ // by default, Medium
+ this.priority = ProviderPriority.MEDIUM;
+ }
}
/**
diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/AbstractDeployPaletteConfigurationHandler.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/AbstractDeployPaletteConfigurationHandler.java
new file mode 100644
index 00000000000..15cf50a7430
--- /dev/null
+++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/AbstractDeployPaletteConfigurationHandler.java
@@ -0,0 +1,369 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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
+ *
+ * Contributors:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.customization.palette.handler;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.gmf.runtime.common.core.service.ProviderPriority;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.TrayDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.uml.diagram.common.Activator;
+import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil;
+import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPalettePreferences;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.XMLMemento;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.statushandlers.StatusManager;
+
+/**
+ * @author RS211865
+ */
+public abstract class AbstractDeployPaletteConfigurationHandler extends AbstractHandler {
+
+ public static class UpdateContentDialog extends TrayDialog {
+ public String paletteName;
+ public ProviderPriority priority;
+ public String editorID;
+ public String requiredProfiles ;
+ public String fileName;
+ private Text nameText;
+ private Text editorText;
+ private Text profilesText;
+ private CCombo priorityCombo;
+
+
+ /**
+ * @param shell
+ * @param priority
+ * @param editorID
+ * @param requiredProfiles
+ */
+ protected UpdateContentDialog(Shell shell, String fileName, String paletteName, ProviderPriority priority, String editorID, Set<String> requiredProfiles) {
+ super(shell);
+ this.fileName = fileName;
+ this.paletteName = paletteName;
+ this.priority = priority;
+ this.editorID = editorID;
+ if(requiredProfiles !=null) {
+ this.requiredProfiles = PaletteUtil.getSerializedProfileList(requiredProfiles);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ if(newShell!=null) {
+ newShell.setText("Configure Deployment of the palette");
+ newShell.setSize(600, 400);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite superComposite = (Composite) super.createDialogArea(parent);
+ Composite composite = new Composite(superComposite, SWT.NONE);
+ composite.setLayout(new GridLayout(2, false));
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+
+ // new grid data will all necessary info
+ Label nameLabel = new Label(composite, SWT.NONE);
+ nameLabel.setText("Name:");
+ nameText = new Text(composite, SWT.BORDER);
+ if(paletteName == null) {
+ paletteName = fileName;
+ }
+ nameText.setText(paletteName);
+ nameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
+
+ Label priorityLabel = new Label(composite, SWT.NONE);
+ priorityLabel.setText("Priority:");
+ priorityCombo = new CCombo(composite, SWT.BORDER);
+ priorityCombo.setEditable(false);
+ priorityCombo.setItems(new String[] {ProviderPriority.LOWEST.getName(), ProviderPriority.LOW.getName(), ProviderPriority.MEDIUM.getName(), ProviderPriority.HIGH.getName(), ProviderPriority.HIGHEST.getName()});
+ if(ProviderPriority.LOWEST.equals(priority)) {
+ priorityCombo.select(0);
+ } else if(ProviderPriority.LOW.equals(priority)) {
+ priorityCombo.select(1);
+ } else if(ProviderPriority.MEDIUM.equals(priority)) {
+ priorityCombo.select(2);
+ } else if(ProviderPriority.HIGH.equals(priority)) {
+ priorityCombo.select(3);
+ } else if(ProviderPriority.HIGHEST.equals(priority)) {
+ priorityCombo.select(4);
+ } else {
+ priorityCombo.select(2); // default = medium
+ }
+ priorityCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
+
+ Label editorLabel = new Label(composite, SWT.NONE);
+ editorLabel.setText("Editor:");
+ editorText = new Text(composite, SWT.BORDER);
+ if(editorID == null) {
+ // TODO: try to see if a Papyrus editor is currently opened?
+ editorID = "";
+ }
+ editorText.setText(editorID);
+ editorText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
+
+ // list of profiles
+ Label profilesLabel = new Label(composite, SWT.NONE);
+ profilesLabel.setText("Profiles:");
+ profilesText = new Text(composite, SWT.BORDER);
+ if(requiredProfiles != null) {
+ profilesText.setText(requiredProfiles);
+ }
+ profilesText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
+
+ return superComposite;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void okPressed() {
+ // updates values
+ if(nameText!=null && ! nameText.isDisposed()) {
+ paletteName = nameText.getText();
+ }
+
+ if(editorText!=null && ! editorText.isDisposed()) {
+ editorID = editorText.getText();
+ }
+
+ if(priorityCombo!=null && ! priorityCombo.isDisposed()) {
+ priority = ProviderPriority.parse(priorityCombo.getText());
+ }
+
+ if(profilesText!=null && ! profilesText.isDisposed()) {
+ requiredProfiles = profilesText.getText();
+ }
+
+ super.okPressed();
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
+ if(!(currentSelection instanceof IStructuredSelection) || currentSelection.isEmpty()) {
+ return null;
+ }
+
+ final IStructuredSelection selection = (IStructuredSelection)currentSelection;
+
+ final Shell activeShell = HandlerUtil.getActiveShell(event);
+
+
+ doExecute(selection, activeShell, new NullProgressMonitor());
+ return null;
+
+ }
+
+ protected void doExecute(IStructuredSelection selection, Shell activeShell, IProgressMonitor monitor) {
+
+ Iterator<?> selectionIterator = selection.iterator();
+
+ MultiStatus result = new MultiStatus(Activator.ID, IStatus.OK, "The palette configuration has been successfully deployed and activated", null);
+
+ while(selectionIterator.hasNext()) {
+ Object selectedElement = selectionIterator.next();
+ if(selectedElement instanceof IAdaptable) {
+ IFile selectedFile = (IFile)((IAdaptable)selectedElement).getAdapter(IFile.class);
+ if(selectedFile == null) {
+ monitor.worked(1);
+ result.add(new Status(IStatus.ERROR, Activator.ID, "The selected element is not a file"));
+ continue;
+ }
+
+
+ String fileName = selectedFile.getFullPath().removeFileExtension().lastSegment();
+ monitor.subTask("Deploy " + fileName);
+ boolean alreadyDeployed = false;
+ // retrieve info => open a dialog, filled by current opened editor ?
+ ProviderPriority priority = getPriority(fileName);
+ if(priority ==null) {
+ priority = ProviderPriority.MEDIUM;
+ } else {
+ alreadyDeployed = true;
+ }
+
+ String editorID = getEditorID(fileName);
+ if(editorID !=null) {
+ alreadyDeployed = true;
+ }
+
+ String paletteName = getPaletteName(fileName);
+ if(paletteName !=null) {
+ alreadyDeployed = true;
+ }
+ Set<String> requiredProfiles = getRequiredProfiles(fileName);
+ if(requiredProfiles !=null && requiredProfiles.size() > 0) {
+ alreadyDeployed = true;
+ }
+ String path = selectedFile.getFullPath().toString();
+
+
+ UpdateContentDialog dialog = new UpdateContentDialog(activeShell, fileName, paletteName, priority, editorID, requiredProfiles);
+ int returnCode = dialog.open();
+ if(Dialog.OK==returnCode) {
+ boolean validUpdate = true;
+
+ // update values from the editor
+ if(dialog.paletteName !=null && dialog.paletteName.length()>0) {
+ paletteName = dialog.paletteName;
+ } else {
+ validUpdate = false;
+ }
+
+ if(dialog.priority !=null ) {
+ priority = dialog.priority;
+ } else {
+ validUpdate = false;
+ }
+
+ if(dialog.editorID !=null && dialog.editorID.length()>0) {
+ editorID = dialog.editorID;
+ }else {
+ validUpdate = false;
+ }
+
+ if(dialog.requiredProfiles !=null && dialog.requiredProfiles.length()>0) {
+ requiredProfiles = PaletteUtil.getProfileSetFromString(dialog.requiredProfiles);
+ }else {
+ requiredProfiles = Collections.emptySet();
+ }
+
+ if(validUpdate) {
+ if(alreadyDeployed) {
+ // update values and set visible again
+ result.add(activatePalette(fileName, paletteName, path, priority, editorID, requiredProfiles));
+ } else {
+ result.add(deployPalette(fileName, paletteName, path, priority, editorID, requiredProfiles));
+ }
+ } else {
+ result.add(new Status(IStatus.ERROR, Activator.ID, "The palette configuration was not deployed, because dialog content was not valid"));
+ }
+ } else {
+ result.add(new Status(IStatus.ERROR, Activator.ID, "The palette configuration was not deployed, because user did cancel the dialog"));
+ }
+
+ }
+ }
+
+ if(result.getChildren().length == 1) {
+ if(result.isOK()) {
+ MessageDialog.openInformation(activeShell, "Success", result.getMessage());
+ } else if(result.getSeverity() < IStatus.ERROR) { //Errors are already logged
+ StatusManager.getManager().handle(result, StatusManager.SHOW);
+ }
+ } else { //Merge the result and specify an appropriate message based on the result
+ if(result.isOK()) {
+ MessageDialog.openInformation(activeShell, "Success", result.getMessage());
+ } else {
+ MultiStatus actualResult = new MultiStatus(Activator.ID, result.getCode(), "Some errors occurred during the deployment", result.getException());
+ actualResult.merge(result);
+ }
+ }
+ }
+
+ /**
+ * @param identifier
+ * @return
+ */
+ protected Set<String> getRequiredProfiles(String identifier) {
+ return PapyrusPalettePreferences.getRequiredProfiles(identifier, getMemento());
+ }
+
+ /**
+ * @param identifier
+ * @return
+ */
+ protected String getPaletteName(String identifier) {
+ return PapyrusPalettePreferences.getPaletteName(identifier, getMemento());
+ }
+
+ /**
+ * @param identifier
+ * @return
+ */
+ protected String getEditorID(String identifier) {
+ return PapyrusPalettePreferences.getEditorID(identifier, getMemento());
+ }
+
+ /**
+ * Warning. Can be <code>null</code>!
+ * @param identifier
+ * @return
+ */
+ protected ProviderPriority getPriority(String identifier) {
+ return PapyrusPalettePreferences.getPalettePriority(identifier, getMemento());
+ }
+
+ protected abstract XMLMemento getMemento();
+
+ /**
+ * @param fileName
+ * @param paletteName
+ * @param path
+ * @param priority
+ * @param editorID
+ * @param requiredProfiles
+ * @return
+ */
+ protected abstract IStatus deployPalette(String fileName, String paletteName, String path, ProviderPriority priority, String editorID, Set<String> requiredProfiles);
+
+ /**
+ * @param fileName
+ * @param paletteName
+ * @param path
+ * @param priority
+ * @param editorID
+ * @param requiredProfiles
+ * @return
+ */
+ protected abstract IStatus activatePalette(String fileName, String paletteName, String path, ProviderPriority priority, String editorID, Set<String> requiredProfiles) ;
+
+}
diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/AbstractUndeployPaletteConfigurationHandler.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/AbstractUndeployPaletteConfigurationHandler.java
new file mode 100644
index 00000000000..df4cd6079ce
--- /dev/null
+++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/AbstractUndeployPaletteConfigurationHandler.java
@@ -0,0 +1,136 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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
+ *
+ * Contributors:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.customization.palette.handler;
+
+import java.util.Iterator;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.uml.diagram.common.Activator;
+import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPalettePreferences;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.XMLMemento;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.statushandlers.StatusManager;
+
+/**
+ * @author RS211865
+ */
+public abstract class AbstractUndeployPaletteConfigurationHandler extends AbstractHandler {
+
+ /**
+ *
+ */
+ public AbstractUndeployPaletteConfigurationHandler() {
+ super();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
+ if(!(currentSelection instanceof IStructuredSelection) || currentSelection.isEmpty()) {
+ return null;
+ }
+
+ final IStructuredSelection selection = (IStructuredSelection)currentSelection;
+
+ final Shell activeShell = HandlerUtil.getActiveShell(event);
+
+
+ doExecute(selection,activeShell, new NullProgressMonitor());
+ return null;
+ }
+
+ protected void doExecute(IStructuredSelection selection, Shell activeShell, IProgressMonitor monitor) {
+ Iterator<?> selectionIterator = selection.iterator();
+
+ MultiStatus result = new MultiStatus(Activator.ID, IStatus.OK, "The palette configuration has been successfully deactivated and undeployed", null);
+
+ while(selectionIterator.hasNext()) {
+ Object selectedElement = selectionIterator.next();
+ if(selectedElement instanceof IAdaptable) {
+ IFile selectedFile = (IFile)((IAdaptable)selectedElement).getAdapter(IFile.class);
+ if(selectedFile == null) {
+ monitor.worked(1);
+ result.add(new Status(IStatus.ERROR, Activator.ID, "The selected element is not a file"));
+ continue;
+ }
+
+
+ String fileName = selectedFile.getFullPath().removeFileExtension().lastSegment();
+ monitor.subTask("Undeploy " + fileName);
+
+ // do not delete.
+ // PapyrusPalettePreferences.deleteWorkspacePalette(fileName);
+
+ // if not deploy, do nothing and onlyh warn
+ String editorId = getEditorID(fileName);
+ if(editorId == null) {
+ // not deployed: cancel the undeploy action
+ MessageDialog.openInformation(activeShell, "Not deployed", "This palette is currently not deployed");
+ result.add(new Status(IStatus.ERROR, Activator.ID, "The palette configuration "+fileName+" was not undeployed already"));
+ } else {
+ result.add(deactivatePalette(fileName, editorId));
+ }
+
+ }
+ }
+
+ if(result.getChildren().length == 1) {
+ if(result.isOK()) {
+ MessageDialog.openInformation(activeShell, "Success", result.getMessage());
+ } else if(result.getSeverity() < IStatus.ERROR) { //Errors are already logged
+ StatusManager.getManager().handle(result, StatusManager.SHOW);
+ }
+ } else { //Merge the result and specify an appropriate message based on the result
+ if(result.isOK()) {
+ MessageDialog.openInformation(activeShell, "Success", result.getMessage());
+ } else {
+ MultiStatus actualResult = new MultiStatus(Activator.ID, result.getCode(), "Some errors occurred during the deployment", result.getException());
+ actualResult.merge(result);
+ }
+ }
+ }
+
+ /**
+ * @return
+ */
+ protected abstract XMLMemento getMemento();
+
+ /**
+ * @param fileName
+ * @return
+ */
+ protected abstract IStatus deactivatePalette(String identifier, String editorId);
+
+ /**
+ * @param identifier
+ * @return
+ */
+ protected String getEditorID(String identifier) {
+ return PapyrusPalettePreferences.getEditorID(identifier, getMemento());
+ }
+}
diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/DeployExtendedPaletteConfigurationHandler.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/DeployExtendedPaletteConfigurationHandler.java
new file mode 100644
index 00000000000..f3c0c17ed6a
--- /dev/null
+++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/DeployExtendedPaletteConfigurationHandler.java
@@ -0,0 +1,58 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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
+ *
+ * Contributors:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.customization.palette.handler;
+
+import java.util.Set;
+
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.gmf.runtime.common.core.service.ProviderPriority;
+import org.eclipse.papyrus.uml.diagram.common.Activator;
+import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPalettePreferences;
+import org.eclipse.ui.XMLMemento;
+
+
+/**
+ * Handler to deploy new configuration of palette based on a XML file
+ */
+public class DeployExtendedPaletteConfigurationHandler extends AbstractDeployPaletteConfigurationHandler implements IHandler {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected IStatus deployPalette(String fileName, String paletteName, String path, ProviderPriority priority, String editorID, Set<String> requiredProfiles) {
+ // just add the palette
+ PapyrusPalettePreferences.addWorkspaceExtendedPalette(fileName, paletteName, path, priority, editorID, requiredProfiles);
+ return new Status(IStatus.OK, Activator.ID, "The palette configuration has been successfully deployed and activated");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected IStatus activatePalette(String fileName, String paletteName, String path, ProviderPriority priority, String editorID, Set<String> requiredProfiles) {
+ PapyrusPalettePreferences.addWorkspaceExtendedPalette(fileName, paletteName, path, priority, editorID, requiredProfiles);
+ PapyrusPalettePreferences.changePaletteVisibility(fileName, editorID, true);
+ return new Status(IStatus.OK, Activator.ID, "The palette configuration was already deployed, it has just been activated");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected XMLMemento getMemento() {
+ return PapyrusPalettePreferences.getExistingWorkspaceExtendedPalettes();
+ }
+} \ No newline at end of file
diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/DeployPaletteConfigurationHandler.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/DeployPaletteConfigurationHandler.java
index 7b5d16d25c9..699d6e9c33e 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/DeployPaletteConfigurationHandler.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/DeployPaletteConfigurationHandler.java
@@ -12,297 +12,47 @@
*****************************************************************************/
package org.eclipse.papyrus.customization.palette.handler;
-import java.util.Iterator;
import java.util.Set;
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.MultiStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.IJobChangeEvent;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.gmf.runtime.common.core.service.ProviderPriority;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.dialogs.TrayDialog;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.papyrus.uml.diagram.common.Activator;
-import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil;
import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPalettePreferences;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CCombo;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.eclipse.ui.statushandlers.StatusManager;
+import org.eclipse.ui.XMLMemento;
/**
- * Handler to deploy new configuration
+ * Handler to deploy new configuration of palette based on a XML file
*/
-public class DeployPaletteConfigurationHandler extends AbstractHandler implements IHandler {
+public class DeployPaletteConfigurationHandler extends AbstractDeployPaletteConfigurationHandler implements IHandler {
/**
* {@inheritDoc}
*/
- public Object execute(ExecutionEvent event) throws ExecutionException {
- ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
- if(!(currentSelection instanceof IStructuredSelection) || currentSelection.isEmpty()) {
- return null;
- }
-
- final IStructuredSelection selection = (IStructuredSelection)currentSelection;
-
- final Shell activeShell = HandlerUtil.getActiveShell(event);
-
-
- doExecute(selection, activeShell, new NullProgressMonitor());
- return null;
-
+ @Override
+ protected IStatus deployPalette(String fileName, String paletteName, String path, ProviderPriority priority, String editorID, Set<String> requiredProfiles) {
+ // just add the palette
+ PapyrusPalettePreferences.addWorkspacePalette(fileName, paletteName, path, priority, editorID, requiredProfiles);
+ return new Status(IStatus.OK, Activator.ID, "The palette configuration has been successfully deployed and activated");
}
- protected void doExecute(IStructuredSelection selection, Shell activeShell, IProgressMonitor monitor) {
-
- Iterator<?> selectionIterator = selection.iterator();
-
- MultiStatus result = new MultiStatus(Activator.ID, IStatus.OK, "The palette configuration has been successfully deployed and activated", null);
-
- while(selectionIterator.hasNext()) {
- Object selectedElement = selectionIterator.next();
- if(selectedElement instanceof IAdaptable) {
- IFile selectedFile = (IFile)((IAdaptable)selectedElement).getAdapter(IFile.class);
- if(selectedFile == null) {
- monitor.worked(1);
- result.add(new Status(IStatus.ERROR, Activator.ID, "The selected element is not a file"));
- continue;
- }
-
-
- String fileName = selectedFile.getFullPath().removeFileExtension().lastSegment();
- monitor.subTask("Deploy " + fileName);
-
- // retrieve info => open a dialog, filled by current opened editor ?
- ProviderPriority priority = PapyrusPalettePreferences.getWorkspacePalettePriority(fileName);
- String editorID = PapyrusPalettePreferences.getWorkspaceEditorID(fileName);
- String paletteName = PapyrusPalettePreferences.getWorkspacePaletteName(fileName);
- Set<String> requiredProfiles = PapyrusPalettePreferences.getRequiredProfiles(fileName);
- String path = selectedFile.getFullPath().toString();
-
-
- UpdateContentDialog dialog = new UpdateContentDialog(activeShell, fileName, paletteName, priority, editorID, requiredProfiles);
- int returnCode = dialog.open();
- if(Dialog.OK==returnCode) {
- boolean validUpdate = true;
- boolean alreadyDeployed = false;
-
- // update values from the editor
- if(dialog.paletteName !=null && dialog.paletteName.length()>0) {
- paletteName = dialog.paletteName;
- alreadyDeployed = true;
- } else {
- validUpdate = false;
- }
-
- if(dialog.priority !=null ) {
- priority = dialog.priority;
- alreadyDeployed = true;
- }else {
- validUpdate = false;
- }
-
- if(dialog.editorID !=null && dialog.editorID.length()>0) {
- editorID = dialog.editorID;
- alreadyDeployed = true;
- }else {
- validUpdate = false;
- }
-
- if(dialog.requiredProfiles !=null && dialog.requiredProfiles.length()>0) {
- requiredProfiles = PaletteUtil.getProfileSetFromString(dialog.requiredProfiles);
- }else {
- validUpdate = false;
- }
-
- if(validUpdate) {
- if(alreadyDeployed) {
- // update values and set visible again
- PapyrusPalettePreferences.addWorkspacePalette(fileName, paletteName, path, priority, editorID, requiredProfiles);
- PapyrusPalettePreferences.changePaletteVisibility(fileName, editorID, true);
- result.add(new Status(IStatus.OK, Activator.ID, "The palette configuration was already deployed, it has just been activated"));
- } else {
- // just add the palette
- PapyrusPalettePreferences.addWorkspacePalette(fileName, paletteName, path, priority, editorID, requiredProfiles);
- result.add(new Status(IStatus.OK, Activator.ID, "The palette configuration has been successfully deployed and activated"));
- }
- } else {
- result.add(new Status(IStatus.ERROR, Activator.ID, "The palette configuration was not deployed, because dialog content was not valid"));
- }
- } else {
- result.add(new Status(IStatus.ERROR, Activator.ID, "The palette configuration was not deployed, because user did cancel the dialog"));
- }
-
- }
- }
-
- if(result.getChildren().length == 1) {
- if(result.isOK()) {
- MessageDialog.openInformation(activeShell, "Success", result.getMessage());
- } else if(result.getSeverity() < IStatus.ERROR) { //Errors are already logged
- StatusManager.getManager().handle(result, StatusManager.SHOW);
- }
- } else { //Merge the result and specify an appropriate message based on the result
- if(result.isOK()) {
- MessageDialog.openInformation(activeShell, "Success", result.getMessage());
- } else {
- MultiStatus actualResult = new MultiStatus(Activator.ID, result.getCode(), "Some errors occurred during the deployment", result.getException());
- actualResult.merge(result);
- }
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected IStatus activatePalette(String fileName, String paletteName, String path, ProviderPriority priority, String editorID, Set<String> requiredProfiles) {
+ PapyrusPalettePreferences.addWorkspacePalette(fileName, paletteName, path, priority, editorID, requiredProfiles);
+ PapyrusPalettePreferences.changePaletteVisibility(fileName, editorID, true);
+ return new Status(IStatus.OK, Activator.ID, "The palette configuration was already deployed, it has just been activated");
}
-
- public static class UpdateContentDialog extends TrayDialog {
- public String paletteName;
- public ProviderPriority priority;
- public String editorID;
- public String requiredProfiles ;
- public String fileName;
- private Text nameText;
- private Text editorText;
- private Text profilesText;
- private CCombo priorityCombo;
-
-
- /**
- * @param shell
- * @param priority
- * @param editorID
- * @param requiredProfiles
- */
- protected UpdateContentDialog(Shell shell, String fileName, String paletteName, ProviderPriority priority, String editorID, Set<String> requiredProfiles) {
- super(shell);
- this.fileName = fileName;
- this.paletteName = paletteName;
- this.priority = priority;
- this.editorID = editorID;
- if(requiredProfiles !=null) {
- this.requiredProfiles = PaletteUtil.getSerializedProfileList(requiredProfiles);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void configureShell(Shell newShell) {
- super.configureShell(newShell);
- if(newShell!=null) {
- newShell.setText("Configure Deployment of the palette");
- newShell.setSize(600, 400);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Control createDialogArea(Composite parent) {
- Composite superComposite = (Composite) super.createDialogArea(parent);
- Composite composite = new Composite(superComposite, SWT.NONE);
- composite.setLayout(new GridLayout(2, false));
- composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
-
- // new grid data will all necessary info
- Label nameLabel = new Label(composite, SWT.NONE);
- nameLabel.setText("Name:");
- nameText = new Text(composite, SWT.BORDER);
- if(paletteName == null) {
- paletteName = fileName;
- }
- nameText.setText(paletteName);
- nameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
-
- Label priorityLabel = new Label(composite, SWT.NONE);
- priorityLabel.setText("Priority:");
- priorityCombo = new CCombo(composite, SWT.BORDER);
- priorityCombo.setEditable(false);
- priorityCombo.setItems(new String[] {ProviderPriority.LOWEST.getName(), ProviderPriority.LOW.getName(), ProviderPriority.MEDIUM.getName(), ProviderPriority.HIGH.getName(), ProviderPriority.HIGHEST.getName()});
- if(ProviderPriority.LOWEST.equals(priority)) {
- priorityCombo.select(0);
- } else if(ProviderPriority.LOW.equals(priority)) {
- priorityCombo.select(1);
- } else if(ProviderPriority.MEDIUM.equals(priority)) {
- priorityCombo.select(2);
- } else if(ProviderPriority.HIGH.equals(priority)) {
- priorityCombo.select(3);
- } else if(ProviderPriority.HIGHEST.equals(priority)) {
- priorityCombo.select(4);
- } else {
- priorityCombo.select(2); // default = medium
- }
- priorityCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
-
- Label editorLabel = new Label(composite, SWT.NONE);
- editorLabel.setText("Editor:");
- editorText = new Text(composite, SWT.BORDER);
- if(editorID == null) {
- // TODO: try to see if a Papyrus editor is currently opened?
- editorID = "";
- }
- editorText.setText(editorID);
- editorText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
-
- // list of profiles
- Label profilesLabel = new Label(composite, SWT.NONE);
- profilesLabel.setText("Profiles:");
- profilesText = new Text(composite, SWT.BORDER);
- if(requiredProfiles != null) {
- profilesText.setText(requiredProfiles);
- }
- profilesText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
-
- return superComposite;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void okPressed() {
- // updates values
- if(nameText!=null && ! nameText.isDisposed()) {
- paletteName = nameText.getText();
- }
-
- if(editorText!=null && ! editorText.isDisposed()) {
- editorID = editorText.getText();
- }
-
- if(priorityCombo!=null && ! priorityCombo.isDisposed()) {
- priority = ProviderPriority.parse(priorityCombo.getText());
- }
-
- if(profilesText!=null && ! profilesText.isDisposed()) {
- requiredProfiles = profilesText.getText();
- }
-
- super.okPressed();
- }
-
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected XMLMemento getMemento() {
+ return PapyrusPalettePreferences.getExistingWorkspacePalettes();
}
} \ No newline at end of file
diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/UndeployExtendedPaletteConfigurationHandler.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/UndeployExtendedPaletteConfigurationHandler.java
new file mode 100644
index 00000000000..1b53065728e
--- /dev/null
+++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/UndeployExtendedPaletteConfigurationHandler.java
@@ -0,0 +1,44 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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
+ *
+ * Contributors:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.customization.palette.handler;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.papyrus.uml.diagram.common.Activator;
+import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPalettePreferences;
+import org.eclipse.ui.XMLMemento;
+
+
+
+/**
+ * Handler to undeploy a palette configured by a EMF model. similar implementation to the XML based palette, because visibility has the same implementation in our case.
+ */
+public class UndeployExtendedPaletteConfigurationHandler extends AbstractUndeployPaletteConfigurationHandler {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected IStatus deactivatePalette(String identifier, String editorId) {
+ PapyrusPalettePreferences.changePaletteVisibility(identifier, editorId, false);
+ return new Status(IStatus.OK, Activator.ID, "The palette configuration "+identifier+" has been successfully deactivated and undeployed");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected XMLMemento getMemento() {
+ return PapyrusPalettePreferences.getExistingWorkspaceExtendedPalettes();
+ }
+}
diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/UndeployPaletteConfigurationHandler.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/UndeployPaletteConfigurationHandler.java
index ca09effadc7..0b305a57c18 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/UndeployPaletteConfigurationHandler.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/handler/UndeployPaletteConfigurationHandler.java
@@ -12,101 +12,31 @@
*****************************************************************************/
package org.eclipse.papyrus.customization.palette.handler;
-import java.util.Iterator;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.MultiStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPalettePreferences;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.handlers.HandlerUtil;
-import org.eclipse.ui.statushandlers.StatusManager;
-
+import org.eclipse.ui.XMLMemento;
/**
- * @author RS211865
+ * Handler to undeploy a palette configured by a XML file
*/
-public class UndeployPaletteConfigurationHandler extends AbstractHandler {
+public class UndeployPaletteConfigurationHandler extends AbstractUndeployPaletteConfigurationHandler {
/**
* {@inheritDoc}
*/
- public Object execute(ExecutionEvent event) throws ExecutionException {
- ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
- if(!(currentSelection instanceof IStructuredSelection) || currentSelection.isEmpty()) {
- return null;
- }
-
- final IStructuredSelection selection = (IStructuredSelection)currentSelection;
-
- final Shell activeShell = HandlerUtil.getActiveShell(event);
-
-
- doExecute(selection,activeShell, new NullProgressMonitor());
- return null;
+ @Override
+ protected IStatus deactivatePalette(String identifier, String editorId) {
+ PapyrusPalettePreferences.changePaletteVisibility(identifier, editorId, false);
+ return new Status(IStatus.OK, Activator.ID, "The palette configuration " + identifier + " has been successfully deactivated and undeployed");
}
- protected void doExecute(IStructuredSelection selection, Shell activeShell, IProgressMonitor monitor) {
- Iterator<?> selectionIterator = selection.iterator();
-
- MultiStatus result = new MultiStatus(Activator.ID, IStatus.OK, "The palette configuration has been successfully deactivated and undeployed", null);
-
- while(selectionIterator.hasNext()) {
- Object selectedElement = selectionIterator.next();
- if(selectedElement instanceof IAdaptable) {
- IFile selectedFile = (IFile)((IAdaptable)selectedElement).getAdapter(IFile.class);
- if(selectedFile == null) {
- monitor.worked(1);
- result.add(new Status(IStatus.ERROR, Activator.ID, "The selected element is not a file"));
- continue;
- }
-
-
- String fileName = selectedFile.getFullPath().removeFileExtension().lastSegment();
- monitor.subTask("Undeploy " + fileName);
-
- // do not delete.
- // PapyrusPalettePreferences.deleteWorkspacePalette(fileName);
-
- // if not deploy, do nothing and onlyh warn
- String editorId = PapyrusPalettePreferences.getWorkspaceEditorID(fileName);
- if(editorId == null) {
- // not deployed: cancel the undeploy action
- MessageDialog.openInformation(activeShell, "Not deployed", "This palette is currently not deployed");
- result.add(new Status(IStatus.ERROR, Activator.ID, "The palette configuration "+fileName+" was not undeployed already"));
- } else {
- // change visibility instead =>
- PapyrusPalettePreferences.changePaletteVisibility(fileName, editorId, false);
- result.add(new Status(IStatus.OK, Activator.ID, "The palette configuration "+fileName+" has been successfully deactivated and undeployed"));
- }
-
- }
- }
-
- if(result.getChildren().length == 1) {
- if(result.isOK()) {
- MessageDialog.openInformation(activeShell, "Success", result.getMessage());
- } else if(result.getSeverity() < IStatus.ERROR) { //Errors are already logged
- StatusManager.getManager().handle(result, StatusManager.SHOW);
- }
- } else { //Merge the result and specify an appropriate message based on the result
- if(result.isOK()) {
- MessageDialog.openInformation(activeShell, "Success", result.getMessage());
- } else {
- MultiStatus actualResult = new MultiStatus(Activator.ID, result.getCode(), "Some errors occurred during the deployment", result.getException());
- actualResult.merge(result);
- }
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected XMLMemento getMemento() {
+ return PapyrusPalettePreferences.getExistingWorkspacePalettes();
}
}

Back to the top