Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpguilet2017-05-19 14:24:13 +0000
committerpguilet2017-06-06 14:26:35 +0000
commit8c82250232a613fb5033c35ce967f9c21f3c48e6 (patch)
tree0641bba3cbae79db5acd78dc583efcdeefab8216 /plugins
parent60fdf351ddb7f72d470106bf953d403d86268a79 (diff)
downloadorg.eclipse.sirius-8c82250232a613fb5033c35ce967f9c21f3c48e6.tar.gz
org.eclipse.sirius-8c82250232a613fb5033c35ce967f9c21f3c48e6.tar.xz
org.eclipse.sirius-8c82250232a613fb5033c35ce967f9c21f3c48e6.zip
[510040] Make available close action on all IFile tree viewer items
The close session action is now available in right click context menu on all aird tree viewer items when they point at an IFile and when not in model explorer view. Bug: 510040 Change-Id: Ic04f1e9c269fd0da82df40ef300e8ff718946bff Signed-off-by: pguilet <pierre.guilet@obeo.fr>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.sirius.ui/plugin.properties2
-rw-r--r--plugins/org.eclipse.sirius.ui/plugin.xml36
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/internal/commands/CloseSessionHandler.java112
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/FileHandledBySessionTester.java56
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/FileSessionFinder.java38
5 files changed, 219 insertions, 25 deletions
diff --git a/plugins/org.eclipse.sirius.ui/plugin.properties b/plugins/org.eclipse.sirius.ui/plugin.properties
index a7714806d8..b39f000f0b 100644
--- a/plugins/org.eclipse.sirius.ui/plugin.properties
+++ b/plugins/org.eclipse.sirius.ui/plugin.properties
@@ -434,6 +434,8 @@ _UI_CreateSibling_description = Create a new sibling of type {0} for the selecte
_UI_PropertyDescriptor_description = The {0} of the {1}
+_UI_CloseSessionCommand_name=Close Session
+_UI_CloseSession_label=Close
_UI_DValidable_type = DValidable
_UI_DNavigable_type = DNavigable
_UI_DStylizable_type = DStylizable
diff --git a/plugins/org.eclipse.sirius.ui/plugin.xml b/plugins/org.eclipse.sirius.ui/plugin.xml
index 6c5c3eebbd..2523d94777 100644
--- a/plugins/org.eclipse.sirius.ui/plugin.xml
+++ b/plugins/org.eclipse.sirius.ui/plugin.xml
@@ -260,7 +260,7 @@
id="org.eclipse.sirius.ui.fileForSessionTester"
type="org.eclipse.core.resources.IFile"
namespace="org.eclipse.sirius.ui"
- properties="isFileForSessionTester"
+ properties="isFileForSessionTester,isSessionFile"
class="org.eclipse.sirius.ui.tools.internal.views.common.FileHandledBySessionTester">
</propertyTester>
<propertyTester
@@ -607,7 +607,13 @@
defaultHandler="org.eclipse.sirius.ui.tools.internal.actions.nature.ModelingToggleNatureAction"
id="org.eclipse.sirius.ui.tools.internal.actions.nature.addRemoveNatureCommand"
name="%_UI_ModelingProjectWizard_label">
- </command>
+ </command>
+ <command
+ categoryId="org.eclipse.ui.category.file"
+ defaultHandler="org.eclipse.sirius.ui.business.internal.commands.CloseSessionHandler"
+ id="org.eclipse.sirius.ui.closeSessionCommand"
+ name="%_UI_CloseSessionCommand_name">
+ </command>
</extension>
@@ -636,5 +642,29 @@
org.eclipse.emf.edit.provider.IItemLabelProvider
org.eclipse.emf.edit.provider.IItemPropertySource"/>
</extension>
-
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.ui.popup.any?before=additions">
+ <command
+ commandId="org.eclipse.sirius.ui.closeSessionCommand"
+ icon="icons/full/others/close.gif"
+ id="org.eclipse.sirius.ui.closeSessionMenuContribution"
+ label="%_UI_CloseSession_label"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <iterate>
+ <adapt
+ type="org.eclipse.core.resources.IResource">
+ <test
+ property="org.eclipse.sirius.ui.isSessionFile">
+ </test>
+ </adapt>
+ </iterate>
+ </visibleWhen>
+ </command>
+ </menuContribution>
+ </extension>
</plugin>
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/internal/commands/CloseSessionHandler.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/internal/commands/CloseSessionHandler.java
new file mode 100644
index 0000000000..d8ba2df739
--- /dev/null
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/internal/commands/CloseSessionHandler.java
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * Copyright (c) 2017 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.ui.business.internal.commands;
+
+import java.lang.reflect.InvocationTargetException;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.List;
+
+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.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.sirius.business.api.session.Session;
+import org.eclipse.sirius.business.api.session.SessionManager;
+import org.eclipse.sirius.ui.tools.internal.commands.CloseUISessionCommand;
+import org.eclipse.sirius.ui.tools.internal.views.common.ContextMenuFiller;
+import org.eclipse.sirius.ui.tools.internal.views.common.FileSessionFinder;
+import org.eclipse.sirius.viewpoint.provider.Messages;
+import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin;
+import org.eclipse.ui.PlatformUI;
+
+import com.google.common.collect.Lists;
+
+/**
+ * Handler allowing to close a session. Used only for items coming from a viewer without CNF capability. For viewer with
+ * CNF capabilities, {@link ContextMenuFiller} is used.
+ *
+ * @author <a href=mailto:pierre.guilet@obeo.fr>Pierre Guilet</a>
+ *
+ */
+public class CloseSessionHandler extends AbstractHandler {
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection();
+ if (selection instanceof StructuredSelection && ((StructuredSelection) selection).getFirstElement() instanceof IFile) {
+ IFile selectedFile = (IFile) ((StructuredSelection) selection).getFirstElement();
+ URI fileURI = URI.createPlatformResourceURI(selectedFile.getFullPath().toString(), true);
+ List<Session> sessionToClose = new ArrayList<>();
+
+ for (Session session : SessionManager.INSTANCE.getSessions()) {
+ if (session.isOpen()) {
+ sessionToClose.add(session);
+ }
+ }
+ for (Session session : sessionToClose) {
+ for (Resource res : session.getAllSessionResources()) {
+ if (fileURI.equals(res.getURI())) {
+ CloseUISessionCommand operation = new CloseUISessionCommand(session);
+ try {
+ new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()).run(true, false, operation);
+ } catch (InvocationTargetException | InterruptedException e) {
+ SiriusEditPlugin.getPlugin().getLog().log(new Status(IStatus.ERROR, SiriusEditPlugin.ID, MessageFormat.format(Messages.CloseSessionsAction_error, e), e));
+ }
+ if (session.isOpen()) {
+ try {
+ new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()).run(true, false, new IRunnableWithProgress() {
+ @Override
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ session.close(SubMonitor.convert(monitor));
+ }
+ });
+ } catch (InvocationTargetException | InterruptedException e) {
+ SiriusEditPlugin.getPlugin().getLog().log(new Status(IStatus.ERROR, SiriusEditPlugin.ID, MessageFormat.format(Messages.CloseSessionsAction_error, e), e));
+ }
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection();
+ if (selection instanceof StructuredSelection) {
+ StructuredSelection structuredSelection = (StructuredSelection) selection;
+ Object firstElement = structuredSelection.getFirstElement();
+ if (firstElement instanceof IFile) {
+ List<Session> relatedSessions = FileSessionFinder.getRelatedSessions(Lists.newArrayList((IFile) firstElement), false, false);
+ for (Session session : relatedSessions) {
+ if (session.isOpen()) {
+ return true;
+ }
+ }
+ }
+ }
+
+ return false;
+ }
+
+}
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/FileHandledBySessionTester.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/FileHandledBySessionTester.java
index 8fe1eb1163..1291e7a620 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/FileHandledBySessionTester.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/FileHandledBySessionTester.java
@@ -11,24 +11,35 @@
package org.eclipse.sirius.ui.tools.internal.views.common;
import java.util.Collections;
+import java.util.List;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.resources.IFile;
import org.eclipse.sirius.business.api.modelingproject.ModelingProject;
import org.eclipse.sirius.business.api.query.FileQuery;
+import org.eclipse.sirius.business.api.session.Session;
+import org.eclipse.sirius.ui.tools.internal.views.modelexplorer.ModelExplorerView;
+import org.eclipse.ui.PlatformUI;
+
+import com.google.common.collect.Lists;
/**
* Property tester to check that an {@link IFile} is:
* <UL>
* <LI>in a modeling project,</LI>
* <LI>or a session resource file,</LI>
- * <LI>or the semantic resource of a transient session (no session file, the
- * session data is in memory).</LI>
+ * <LI>or is an aird file loaded in a session</LI>
+ * <LI>or the semantic resource of a transient session (no session file, the session data is in memory).</LI>
* </UL>
*
* @author mporhel
*/
public class FileHandledBySessionTester extends PropertyTester {
+ /**
+ * Property verifying that a given element in an IFile representing an aird that has a corresponding session
+ * loading.
+ */
+ private static final String SESSION_FILE_PROPERTY = "isSessionFile"; //$NON-NLS-1$
/**
* Constructor.
@@ -39,18 +50,43 @@ public class FileHandledBySessionTester extends PropertyTester {
/**
* {@inheritDoc}
*/
+ @Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
- boolean result = false;
- if (receiver instanceof IFile) {
- IFile receiverFile = (IFile) receiver;
+ if (SESSION_FILE_PROPERTY.equals(property)) {
+ return isSessionFile(receiver);
+ } else {
+ boolean result = false;
+ if (receiver instanceof IFile) {
+ IFile receiverFile = (IFile) receiver;
- // Modeling project should show expansion arrows during session load
- if (ModelingProject.hasModelingProjectNature(receiverFile.getProject())) {
- result = true;
+ // Modeling project should show expansion arrows during session load
+ if (ModelingProject.hasModelingProjectNature(receiverFile.getProject())) {
+ result = true;
+ } else {
+ result = new FileQuery(receiverFile.getFileExtension()).isSessionResourceFile() || !FileSessionFinder.getSelectedSessions(Collections.singletonList(receiverFile)).isEmpty();
+ }
+ }
+ return result;
+ }
+ }
+
+ /**
+ * Returns true if the given element in an IFile representing a session file.
+ *
+ * @param element
+ * element to test.
+ * @return true if the given element in an IFile representing a session file. False otherwise.
+ */
+ private boolean isSessionFile(Object element) {
+ boolean isSessionResourceFile = false;
+ if (!ModelExplorerView.class.getTypeName().equals(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getClass().getTypeName()) && element instanceof IFile) {
+ List<Session> relatedSessions = FileSessionFinder.getRelatedSessions(Lists.newArrayList((IFile) element), false, false);
+ if (!relatedSessions.isEmpty()) {
+ isSessionResourceFile = true;
} else {
- result = new FileQuery(receiverFile.getFileExtension()).isSessionResourceFile() || !FileSessionFinder.getSelectedSessions(Collections.singletonList(receiverFile)).isEmpty();
+ isSessionResourceFile = new FileQuery((IFile) element).isSessionResourceFile();
}
}
- return result;
+ return isSessionResourceFile;
}
}
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/FileSessionFinder.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/FileSessionFinder.java
index 9aa2c95176..7863c3c1db 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/FileSessionFinder.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/FileSessionFinder.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 THALES GLOBAL SERVICES.
+ * Copyright (c) 2011, 2017 THALES GLOBAL SERVICES.
* 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
@@ -41,9 +41,8 @@ public final class FileSessionFinder {
}
/**
- * Retrieve the open sessions in the given list by looking for
- * {@link Session}s and/or *.aird {@link IFile}s (only main aird for non
- * modeling projects) or transient session with semantic files in selection.
+ * Retrieve the open sessions in the given list by looking for {@link Session}s and/or *.aird {@link IFile}s (only
+ * main aird for non modeling projects) or transient session with semantic files in selection.
*
* @param listObject
* list of objects
@@ -60,7 +59,7 @@ public final class FileSessionFinder {
if (selected instanceof Session) {
selectedSessions.add((Session) selected);
} else if (selected instanceof IFile) {
- Collection<Session> fileSessions = getSessionFromFile((IFile) selected, false);
+ Collection<Session> fileSessions = getSessionFromFile((IFile) selected, false, true);
if (fileSessions != null && !fileSessions.isEmpty()) {
selectedSessions.addAll(fileSessions);
}
@@ -77,6 +76,22 @@ public final class FileSessionFinder {
* @return list of session associated to the given files.
*/
public static List<Session> getRelatedSessions(final Collection<IFile> files) {
+ return getRelatedSessions(files, true, true);
+ }
+
+ /**
+ * Retrieve the open sessions related to the given file list.
+ *
+ * @param files
+ * list of files
+ * @param getOnlyMainSessionForNoModelingProject
+ * true if no main sessions should be returned if such sessions exist for an IFile representing a session
+ * and coming from a no modeling project. False otherwise.
+ * @param lookFromSemanticAndControlled
+ * look from semantic and controlled
+ * @return list of session associated to the given files.
+ */
+ public static List<Session> getRelatedSessions(final Collection<IFile> files, boolean lookFromSemanticAndControlled, boolean getOnlyMainSessionForNoModelingProject) {
final List<Session> selectedSessions = Lists.newArrayList();
if (files == null) {
@@ -85,7 +100,7 @@ public final class FileSessionFinder {
for (final IFile file : files) {
if (file != null) {
- Collection<Session> fileSessions = getSessionFromFile(file, true);
+ Collection<Session> fileSessions = getSessionFromFile(file, lookFromSemanticAndControlled, getOnlyMainSessionForNoModelingProject);
if (fileSessions != null && !fileSessions.isEmpty()) {
selectedSessions.addAll(fileSessions);
}
@@ -95,22 +110,21 @@ public final class FileSessionFinder {
}
/**
- * Get session linked to an aird or transient session linked to its semantic
- * resource.
+ * Get session linked to an aird or transient session linked to its semantic resource.
*/
- private static Collection<Session> getSessionFromFile(IFile file, boolean lookFromSemanticAndControlled) {
+ private static Collection<Session> getSessionFromFile(IFile file, boolean lookFromSemanticAndControlled, boolean getOnlyMainSessionForNoModelingProject) {
Collection<Session> sessions = Sets.newLinkedHashSet();
boolean lookForTransientSession = !SiriusUtil.SESSION_RESOURCE_EXTENSION.equals(file.getFileExtension());
URI fileURI = getFileUri(file);
for (Session session : SessionManager.INSTANCE.getSessions()) {
- if (checkedSession(session, file, fileURI, lookForTransientSession, lookFromSemanticAndControlled)) {
+ if (checkedSession(session, file, fileURI, lookForTransientSession, lookFromSemanticAndControlled, getOnlyMainSessionForNoModelingProject)) {
sessions.add(session);
}
}
return sessions;
}
- private static boolean checkedSession(Session session, IFile file, URI fileURI, boolean lookForTransientSession, boolean lookFromSemantic) {
+ private static boolean checkedSession(Session session, IFile file, URI fileURI, boolean lookForTransientSession, boolean lookFromSemantic, boolean getOnlyMainSessionForNoModelingProject) {
boolean foundSession = false;
Resource sessionResource = session.getSessionResource();
@@ -124,7 +138,7 @@ public final class FileSessionFinder {
foundSession = checkSession(fileURI, resourceToCheck);
} else {
foundSession = sessionResource.getURI().equals(fileURI);
- if (!foundSession && ModelingProject.hasModelingProjectNature(file.getProject())) {
+ if (!foundSession && (!getOnlyMainSessionForNoModelingProject || (getOnlyMainSessionForNoModelingProject && ModelingProject.hasModelingProjectNature(file.getProject())))) {
foundSession = checkSession(fileURI, session.getAllSessionResources());
}
}

Back to the top