Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2014-03-11 12:42:28 +0000
committerCamille Letavernier2014-04-29 13:50:42 +0000
commit8ac0c599683e975713f09c629fc361f5b53b758d (patch)
tree2ec04a405d2470bf983a5b877d4572a8c4d2b067 /plugins/uml/modelexplorer
parent0204455171c09791e359b7484225bd81249df92f (diff)
downloadorg.eclipse.papyrus-8ac0c599683e975713f09c629fc361f5b53b758d.tar.gz
org.eclipse.papyrus-8ac0c599683e975713f09c629fc361f5b53b758d.tar.xz
org.eclipse.papyrus-8ac0c599683e975713f09c629fc361f5b53b758d.zip
320908: [Model Explorer] Newly created objects (via "New Child" menu)
shall get focus and be in rename mode https://bugs.eclipse.org/bugs/show_bug.cgi?id=320908
Diffstat (limited to 'plugins/uml/modelexplorer')
-rw-r--r--plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer/src/org/eclipse/papyrus/uml/modelexplorer/handler/AbstractUmlModelExplorerCreateCommandHandler.java64
1 files changed, 61 insertions, 3 deletions
diff --git a/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer/src/org/eclipse/papyrus/uml/modelexplorer/handler/AbstractUmlModelExplorerCreateCommandHandler.java b/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer/src/org/eclipse/papyrus/uml/modelexplorer/handler/AbstractUmlModelExplorerCreateCommandHandler.java
index 5a0e4900995..a90a7a00d1e 100644
--- a/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer/src/org/eclipse/papyrus/uml/modelexplorer/handler/AbstractUmlModelExplorerCreateCommandHandler.java
+++ b/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer/src/org/eclipse/papyrus/uml/modelexplorer/handler/AbstractUmlModelExplorerCreateCommandHandler.java
@@ -1,6 +1,6 @@
/*****************************************************************************
* 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
@@ -11,9 +11,23 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.modelexplorer.handler;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.papyrus.infra.core.utils.AdapterUtils;
+import org.eclipse.papyrus.infra.widgets.util.IRevealSemanticElement;
+import org.eclipse.papyrus.infra.widgets.util.NavigationTarget;
+import org.eclipse.papyrus.infra.widgets.util.RevealSemanticElementWrapper;
import org.eclipse.papyrus.uml.modelexplorer.util.ModelExplorerUtils;
import org.eclipse.papyrus.uml.service.types.handlers.AbstractUmlCreateCommandHandler;
import org.eclipse.papyrus.uml.service.types.utils.ICommandContext;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.uml2.uml.Element;
+
+import com.google.common.base.Optional;
/**
@@ -23,15 +37,59 @@ import org.eclipse.papyrus.uml.service.types.utils.ICommandContext;
public abstract class AbstractUmlModelExplorerCreateCommandHandler extends AbstractUmlCreateCommandHandler {
/**
- *
+ *
* @see org.eclipse.papyrus.uml.service.types.handlers.AbstractCommandHandler#getCommandContext()
- *
+ *
* @return
*/
+ @Override
protected ICommandContext getCommandContext() {
return ModelExplorerUtils.getSelectionCommandContext();
}
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ Object result = super.execute(event);
+
+ if(result instanceof Element) {
+ handleElementsCreated(Collections.singleton((Element)result), event);
+ } else if(result instanceof Collection<?>) {
+ handleElementsCreated((Collection<?>)result, event);
+ }
+
+ return result;
+ }
+
+ protected void handleElementsCreated(Collection<?> elements, ExecutionEvent event) {
+ if(elements.isEmpty()) {
+ return;
+ }
+ NavigationTarget target = getNavigationTarget(event);
+ if(target == null) {
+ return;
+ }
+
+ target.revealElement(elements);
+ }
+
+ protected NavigationTarget getNavigationTarget(ExecutionEvent event) {
+ IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
+ if(activePart == null) {
+ return null;
+ }
+
+ Optional<NavigationTarget> navigationTarget = AdapterUtils.adapt(activePart, NavigationTarget.class);
+ if(navigationTarget.isPresent()) {
+ return navigationTarget.get();
+ }
+
+ Optional<IRevealSemanticElement> revealSemantic = AdapterUtils.adapt(activePart, IRevealSemanticElement.class);
+ if(revealSemantic.isPresent()) {
+ return new RevealSemanticElementWrapper(revealSemantic.get());
+ }
+
+ return null;
+ }
}

Back to the top