Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMélanie Bats2016-10-03 08:33:58 +0000
committerPierre-Charles David2016-10-05 06:31:42 +0000
commit28884344a71a0e35f90f91d970519d1e06e8e522 (patch)
tree68c07926307bc5b3c53f42d080a8e81b9e6b54a0
parent84f041de4fd9aafffc26c95f4fbb0b1f7b63eb88 (diff)
downloadorg.eclipse.sirius-28884344a71a0e35f90f91d970519d1e06e8e522.tar.gz
org.eclipse.sirius-28884344a71a0e35f90f91d970519d1e06e8e522.tar.xz
org.eclipse.sirius-28884344a71a0e35f90f91d970519d1e06e8e522.zip
[496061] Add action to inline default properties rules
Add a new "Import>Default properties view description" menu which imports the default properties view rules under a selected Group. Bug: 496061 Change-Id: I0c8c791c73359d591dff53658624419b43772b89 Signed-off-by: Mélanie Bats <melanie.bats@obeo.fr> Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.editor.properties/META-INF/MANIFEST.MF8
-rw-r--r--plugins/org.eclipse.sirius.editor.properties/plugin.properties3
-rw-r--r--plugins/org.eclipse.sirius.editor.properties/plugin.xml5
-rw-r--r--plugins/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/editor/properties/Messages.java39
-rw-r--r--plugins/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/editor/properties/SiriusEditorPropertiesPlugin.java67
-rw-r--r--plugins/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/editor/properties/tools/internal/menu/ImportingDefaultPropertiesViewDescriptionAction.java122
-rw-r--r--plugins/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/editor/properties/tools/internal/menu/ImportingDefaultPropertiesViewDescriptionCommand.java59
-rw-r--r--plugins/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/editor/properties/tools/internal/menu/ImportingMenu.java72
8 files changed, 372 insertions, 3 deletions
diff --git a/plugins/org.eclipse.sirius.editor.properties/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.editor.properties/META-INF/MANIFEST.MF
index d356f2bbae..e07f94f2ca 100644
--- a/plugins/org.eclipse.sirius.editor.properties/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.sirius.editor.properties/META-INF/MANIFEST.MF
@@ -17,7 +17,9 @@ Require-Bundle: com.google.guava;bundle-version="[11.0.2,16.0)",
org.eclipse.ui.ide;bundle-version="3.5.200",
org.eclipse.ui.views.properties.tabbed;bundle-version="3.5.300",
org.eclipse.ui.workbench.texteditor;bundle-version="3.8.0",
- org.eclipse.sirius.ext.swt;bundle-version="4.0.0"
+ org.eclipse.sirius.ext.swt;bundle-version="4.0.0",
+ org.eclipse.sirius.ui.properties;bundle-version="4.1.0",
+ org.eclipse.sirius.ext.base;bundle-version="4.1.0"
Export-Package: org.eclipse.sirius.editor.properties.tools.internal.menu;version="4.1.0";x-internal:=true,
org.eclipse.sirius.properties.editor.properties.filters.properties.buttondescription;version="4.1.0";x-internal:=true,
org.eclipse.sirius.properties.editor.properties.filters.properties.checkboxdescription;version="4.1.0";x-internal:=true,
@@ -74,4 +76,6 @@ Export-Package: org.eclipse.sirius.editor.properties.tools.internal.menu;version
org.eclipse.sirius.properties.editor.properties.sections.properties.widgetaction;version="4.1.0";x-internal:=true,
org.eclipse.sirius.properties.editor.properties.sections.properties.widgetconditionalstyle;version="4.1.0";x-internal:=true,
org.eclipse.sirius.properties.editor.properties.sections.properties.widgetdescription;version="4.1.0";x-internal:=true,
- org.eclipse.sirius.properties.editor.properties.sections.properties.widgetstyle;version="4.1.0";x-internal:=true
+ org.eclipse.sirius.properties.editor.properties.sections.properties.widgetstyle;version="4.1.0";x-internal:=true,
+ org.eclipse.sirius.editor.properties;version="4.1.0";x-internal:=true
+Bundle-Activator: org.eclipse.sirius.editor.properties.SiriusEditorPropertiesPlugin$Implementation
diff --git a/plugins/org.eclipse.sirius.editor.properties/plugin.properties b/plugins/org.eclipse.sirius.editor.properties/plugin.properties
index 5c6e98ae03..20e4862888 100644
--- a/plugins/org.eclipse.sirius.editor.properties/plugin.properties
+++ b/plugins/org.eclipse.sirius.editor.properties/plugin.properties
@@ -14,3 +14,6 @@ providerName = Eclipse Modeling Project
viewpoint.tab.label.name = Label
viewpoint.tab.widget.name = Widget
+
+ImportingDefaultPropertiesViewDescriptionCommand_text = Default Properties View Description
+ImportingMenu_label = Import \ No newline at end of file
diff --git a/plugins/org.eclipse.sirius.editor.properties/plugin.xml b/plugins/org.eclipse.sirius.editor.properties/plugin.xml
index f34fbe1a68..8013f0acb1 100644
--- a/plugins/org.eclipse.sirius.editor.properties/plugin.xml
+++ b/plugins/org.eclipse.sirius.editor.properties/plugin.xml
@@ -582,6 +582,9 @@
<builder class="org.eclipse.sirius.editor.properties.tools.internal.menu.WidgetsMenuBuilder" />
<builder class="org.eclipse.sirius.editor.properties.tools.internal.menu.StyleMenuBuilder" />
<builder class="org.eclipse.sirius.editor.properties.tools.internal.menu.LayoutMenuBuilder" />
+ <builder
+ class="org.eclipse.sirius.editor.properties.tools.internal.menu.ImportingMenu">
+ </builder>
</extension>
</plugin>
-<!-- End of user code plugin.xml end specifics --> \ No newline at end of file
+<!-- End of user code plugin.xml end specifics -->
diff --git a/plugins/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/editor/properties/Messages.java b/plugins/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/editor/properties/Messages.java
new file mode 100644
index 0000000000..9e4435efb3
--- /dev/null
+++ b/plugins/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/editor/properties/Messages.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.sirius.editor.properties;
+
+import org.eclipse.sirius.ext.base.I18N;
+import org.eclipse.sirius.ext.base.I18N.TranslatableMessage;
+
+/**
+ * Helper class to obtains translated strings.
+ *
+ * @author mbats
+ */
+public final class Messages {
+
+ static {
+ I18N.initializeMessages(Messages.class, SiriusEditorPropertiesPlugin.INSTANCE);
+ }
+
+ // CHECKSTYLE:OFF
+ @TranslatableMessage
+ public static String ImportingDefaultPropertiesViewDescriptionCommand_text;
+
+ @TranslatableMessage
+ public static String ImportingMenu_label;
+
+ // CHECKSTYLE:ON
+
+ private Messages() {
+ // Prevents instanciation.
+ }
+}
diff --git a/plugins/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/editor/properties/SiriusEditorPropertiesPlugin.java b/plugins/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/editor/properties/SiriusEditorPropertiesPlugin.java
new file mode 100644
index 0000000000..417f1abd29
--- /dev/null
+++ b/plugins/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/editor/properties/SiriusEditorPropertiesPlugin.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.sirius.editor.properties;
+
+import org.eclipse.emf.common.EMFPlugin;
+import org.eclipse.emf.common.ui.EclipseUIPlugin;
+import org.eclipse.emf.common.util.ResourceLocator;
+
+/**
+ * This is the central singleton for the SiriusEditorProperties edit plugin.
+ *
+ * @author mbats
+ */
+public final class SiriusEditorPropertiesPlugin extends EMFPlugin {
+ /**
+ * The plug-in ID.
+ */
+ public static final String PLUGIN_ID = " org.eclipse.sirius.editor.properties"; //$NON-NLS-1$
+
+ /**
+ * Singleton instance.
+ */
+ public static final SiriusEditorPropertiesPlugin INSTANCE = new SiriusEditorPropertiesPlugin();
+
+ private static Implementation plugin;
+
+ /**
+ * Create the instance.
+ */
+ public SiriusEditorPropertiesPlugin() {
+ super(new ResourceLocator[0]);
+ }
+
+ @Override
+ public ResourceLocator getPluginResourceLocator() {
+ return plugin;
+ }
+
+ /**
+ * Returns the singleton instance of the Eclipse plugin.
+ *
+ * @return the singleton instance.
+ */
+ public static Implementation getPlugin() {
+ return plugin;
+ }
+
+ /**
+ * The actual implementation of the Eclipse <b>Plugin</b>.
+ */
+ public static class Implementation extends EclipseUIPlugin {
+ /**
+ * Creates an instance.
+ */
+ public Implementation() {
+ plugin = this;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/editor/properties/tools/internal/menu/ImportingDefaultPropertiesViewDescriptionAction.java b/plugins/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/editor/properties/tools/internal/menu/ImportingDefaultPropertiesViewDescriptionAction.java
new file mode 100644
index 0000000000..7d49e8d8f2
--- /dev/null
+++ b/plugins/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/editor/properties/tools/internal/menu/ImportingDefaultPropertiesViewDescriptionAction.java
@@ -0,0 +1,122 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.sirius.editor.properties.tools.internal.menu;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.UnexecutableCommand;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.ui.action.StaticSelectionCommandAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.sirius.viewpoint.description.Group;
+import org.eclipse.ui.IEditorPart;
+
+/**
+ * Action for inlining the default rules in the current VSM.
+ *
+ * @author mbats
+ *
+ */
+public class ImportingDefaultPropertiesViewDescriptionAction extends StaticSelectionCommandAction {
+
+ /**
+ * A field indicating if the selection used to construct the action is
+ * valid.
+ */
+ private boolean isSelectionValid;
+
+ /**
+ * Create a new importing action.
+ *
+ * @param editor
+ * the current editor.
+ * @param selection
+ * the current selection.
+ */
+ public ImportingDefaultPropertiesViewDescriptionAction(final IEditorPart editor, final ISelection selection) {
+ super(editor);
+ isSelectionValid = true;
+ configureAction(selection);
+ }
+
+ @Override
+ public String getText() {
+ if (command != null) {
+ return command.getLabel();
+ } else {
+ return super.getText();
+ }
+ }
+
+ @Override
+ protected Command createActionCommand(final EditingDomain editingDomain, final Collection<?> selection) {
+
+ final Collection<EObject> selected = new ArrayList<EObject>();
+ for (final Object object : selection) {
+ if (object instanceof EObject) {
+ selected.add((EObject) object);
+ }
+ }
+ return buildActionCommand(editingDomain, selected);
+ }
+
+ /**
+ * Build the command for the importing action.
+ *
+ * @param editingDomain
+ * the current editing domain.
+ * @param selection
+ * the selected eobjects
+ * @return the builded action command.
+ */
+ protected Command buildActionCommand(final EditingDomain editingDomain, final Collection<EObject> selection) {
+ Command result = UnexecutableCommand.INSTANCE;
+ this.isSelectionValid = false;
+ if (selection.size() == 1) {
+ final EObject selectedEObject = selection.iterator().next();
+ if (selectedEObject instanceof Group) {
+ this.isSelectionValid = true;
+ result = new ImportingDefaultPropertiesViewDescriptionCommand(editingDomain.getResourceSet(), (Group) selectedEObject);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * <p>
+ * Indicates if the selection used to build the action is valid.
+ * </p>
+ *
+ * <p>
+ * This information will be used by the
+ * {@link ImportingMenu}
+ * to decide whether this action should be added to the menu or not. <br/>
+ * 4 cases can happen :
+ * <ul>
+ * <li>isSelectionValid && isEnabled -> the Action is shown an can be
+ * executed</li>
+ * <li>isSelectionValid && !(isEnabled) -> the Action is shown an cannot be
+ * executed</li>
+ * <li>!(isSelectionValid) && isEnabled -> this case cannot happen</li>
+ * <li>!(isSelectionValid) && !(isEnabled) -> the Action hidden (not added
+ * to the refactor menu)</li>
+ * </ul>
+ * </p>
+ *
+ * @return <code>true</code> if the selection is valid.
+ */
+ public boolean isSelectionValid() {
+ return this.isSelectionValid;
+ }
+}
diff --git a/plugins/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/editor/properties/tools/internal/menu/ImportingDefaultPropertiesViewDescriptionCommand.java b/plugins/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/editor/properties/tools/internal/menu/ImportingDefaultPropertiesViewDescriptionCommand.java
new file mode 100644
index 0000000000..b1d61ead16
--- /dev/null
+++ b/plugins/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/editor/properties/tools/internal/menu/ImportingDefaultPropertiesViewDescriptionCommand.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.sirius.editor.properties.tools.internal.menu;
+
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.sirius.editor.properties.Messages;
+import org.eclipse.sirius.editor.tools.api.menu.AbstractUndoRecordingCommand;
+import org.eclipse.sirius.properties.ViewExtensionDescription;
+import org.eclipse.sirius.ui.properties.internal.tabprovider.SiriusTabDescriptorProvider;
+import org.eclipse.sirius.viewpoint.description.Group;
+
+/**
+ * Command inlining the default properties view description.
+ *
+ * @author mbats
+ *
+ */
+public class ImportingDefaultPropertiesViewDescriptionCommand extends AbstractUndoRecordingCommand {
+
+ private final Group group;
+
+ /**
+ * Create a new command.
+ *
+ * @param set
+ * the current resourceSet.
+ * @param group
+ * the group element in which the rules must be imported.
+ */
+ public ImportingDefaultPropertiesViewDescriptionCommand(final ResourceSet set, final Group group) {
+ super(set);
+ this.group = group;
+ }
+
+ @Override
+ protected void doExecute() {
+ // Load the default rules
+ ViewExtensionDescription defaults = SiriusTabDescriptorProvider.getDefaultRules();
+
+ // Copy the default rules into the selected group
+ ViewExtensionDescription ved = EcoreUtil.copy(defaults);
+ group.getExtensions().add(ved);
+
+ }
+
+ @Override
+ protected String getText() {
+ return Messages.ImportingDefaultPropertiesViewDescriptionCommand_text;
+ }
+}
diff --git a/plugins/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/editor/properties/tools/internal/menu/ImportingMenu.java b/plugins/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/editor/properties/tools/internal/menu/ImportingMenu.java
new file mode 100644
index 0000000000..9cd39f58c4
--- /dev/null
+++ b/plugins/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/editor/properties/tools/internal/menu/ImportingMenu.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.sirius.editor.properties.tools.internal.menu;
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.eclipse.emf.edit.command.CommandParameter;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.sirius.editor.properties.Messages;
+import org.eclipse.sirius.editor.tools.api.menu.AbstractMenuBuilder;
+import org.eclipse.ui.IEditorPart;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Sets;
+
+/**
+ * The menu for the import actions.
+ *
+ * @author mbats
+ */
+public class ImportingMenu extends AbstractMenuBuilder {
+
+ /**
+ * Import menu label.
+ */
+ public static final String IMPORTING_MENU_LABEL = Messages.ImportingMenu_label;
+
+ @Override
+ public String getLabel() {
+ return IMPORTING_MENU_LABEL;
+ }
+
+ @Override
+ public int getPriority() {
+ return AbstractMenuBuilder.OTHERS;
+ }
+
+ @Override
+ public void update(final Collection newChildDescriptors, final ISelection selection, final IEditorPart editor) {
+ depopulate();
+ advancedChildActions = generateImportingActions(selection, editor);
+ }
+
+ private Collection<?> generateImportingActions(final ISelection selection, final IEditorPart editor) {
+ // We first build all candidate Actions
+ Set<ImportingDefaultPropertiesViewDescriptionAction> allActions = Sets.newLinkedHashSet();
+ allActions.add(new ImportingDefaultPropertiesViewDescriptionAction(editor, selection));
+
+ // We only add to the menu the actions that have a valid selection
+ return Sets.filter(allActions, new Predicate<ImportingDefaultPropertiesViewDescriptionAction>() {
+
+ public boolean apply(ImportingDefaultPropertiesViewDescriptionAction candidateAction) {
+ return candidateAction.isSelectionValid();
+ }
+ });
+ }
+
+ @Override
+ protected boolean isMine(final CommandParameter object) {
+ // not relevant here
+ return false;
+ }
+}

Back to the top