diff --git a/bundles/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/dnd/ModelDropListener.java b/bundles/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/dnd/ModelDropListener.java index 3f5b7976de..c3c9ac06fc 100644 --- a/bundles/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/dnd/ModelDropListener.java +++ b/bundles/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/dnd/ModelDropListener.java @@ -18,6 +18,7 @@ import java.util.Collection; import java.util.Objects; +import org.eclipse.jface.viewers.AbstractTreeViewer; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerDropAdapter; @@ -26,22 +27,22 @@ import org.eclipse.vorto.perspective.view.ModelProjectTreeViewer; /** - * A drop listener that can be configured with : - * - An allowed target : the target class allowed for this drop listener - * - Drop actions that consist of a validator and the actual action to be performed if - * the validator allows the drop. + * A drop listener that can be configured with : - An allowed target : the + * target class allowed for this drop listener - Drop actions that consist of a + * validator and the actual action to be performed if the validator allows the + * drop. * */ public class ModelDropListener extends ViewerDropAdapter { private Class allowedTarget; - + private Collection dropActors = new ArrayList(); - + public ModelDropListener(Viewer viewer) { super(viewer); } - + public ModelDropListener setAllowedTarget(Class allowedTarget) { this.allowedTarget = allowedTarget; return this; @@ -54,55 +55,68 @@ public ModelDropListener addDropAction(IDropValidator validator, IDropAction act return this; } + @SuppressWarnings("unchecked") public boolean performDrop(Object data) { Object target = getTarget(); if (data instanceof IStructuredSelection) { - Object droppedResource = ((IStructuredSelection) data) - .getFirstElement(); + Object droppedResource = ((IStructuredSelection) data).getFirstElement(); IModelElement result = null; - for(DropSourceValidatorAndAction dropActor : dropActors) { + for (DropSourceValidatorAndAction dropActor : dropActors) { if (dropActor.validator.allow(target, droppedResource)) { result = dropActor.action.performDrop(target, droppedResource); break; } } - + if (result != null) { - ModelProjectTreeViewer viewer = (ModelProjectTreeViewer)this.getViewer(); - viewer.getLocalModelWorkspace().refresh(); - viewer.expandToLevel(result, 2); - - return true; + ModelProjectTreeViewer viewer = (ModelProjectTreeViewer) this.getViewer(); + viewer.getLocalModelWorkspace().refreshCurrent(); + IModelElement targetModelElement = findTarget((IModelElement) target, + (Collection) viewer.getInput()); + if (targetModelElement != null) { + viewer.expandToLevel(targetModelElement, 1); + } + + return true; } - + } - + return false; } + private IModelElement findTarget(IModelElement target, Collection inputModelElements) { + for(IModelElement e : inputModelElements) { + if (e.getId().equals(target.getId())) { + return e; + } + } + return null; + } + private Object getTarget() { Object target = this.getCurrentTarget(); if (target == null) { Viewer viewer = this.getViewer(); if (viewer instanceof ModelProjectTreeViewer) { - target = ((ModelProjectTreeViewer)viewer).getLocalModelWorkspace().getProjectBrowser().getSelectedProject(); + target = ((ModelProjectTreeViewer) viewer).getLocalModelWorkspace().getProjectBrowser() + .getSelectedProject(); } } - + return target; } - public boolean validateDrop(Object target, int operation, - TransferData transferType) { + public boolean validateDrop(Object target, int operation, TransferData transferType) { return allowedTarget == null || allowedTarget.isInstance(target); } private class DropSourceValidatorAndAction { IDropValidator validator; IDropAction action; - public DropSourceValidatorAndAction(IDropValidator validator, - IDropAction action) { + + public DropSourceValidatorAndAction(IDropValidator validator, IDropAction action) { this.validator = validator; this.action = action; } diff --git a/bundles/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/dnd/ModelDropListenerFactory.java b/bundles/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/dnd/ModelDropListenerFactory.java index 67bcd24686..0c9ff28cbf 100644 --- a/bundles/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/dnd/ModelDropListenerFactory.java +++ b/bundles/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/dnd/ModelDropListenerFactory.java @@ -26,7 +26,6 @@ import org.eclipse.vorto.perspective.dnd.dropaction.AddSharedReferenceDropAction; import org.eclipse.vorto.perspective.dnd.dropaction.RepositoryResourceDropAction; import org.eclipse.vorto.perspective.dnd.dropvalidator.DatatypeValidator; -import org.eclipse.vorto.perspective.dnd.dropvalidator.ModelTypeValidator; import org.eclipse.vorto.perspective.dnd.dropvalidator.TargetClassModelTypeValidator; import org.eclipse.vorto.perspective.dnd.dropvalidator.TargetClassSourceClassValidator; diff --git a/bundles/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/view/ILocalModelWorkspace.java b/bundles/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/view/ILocalModelWorkspace.java index ac6f701464..094d64769f 100644 --- a/bundles/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/view/ILocalModelWorkspace.java +++ b/bundles/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/view/ILocalModelWorkspace.java @@ -29,6 +29,11 @@ public interface ILocalModelWorkspace { * refreshes the model browser by reloading all models for the selected project */ void refresh(); + + /** + * Only refreshes the current selected project + */ + void refreshCurrent(); public interface IModelProjectBrowser { diff --git a/bundles/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/view/ProjectSelectionViewPart.java b/bundles/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/view/ProjectSelectionViewPart.java index b765061903..8f3c845c33 100644 --- a/bundles/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/view/ProjectSelectionViewPart.java +++ b/bundles/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/view/ProjectSelectionViewPart.java @@ -111,12 +111,12 @@ public String getText(Object element) { }); projectSelectionViewer.setContentProvider(ArrayContentProvider.getInstance()); - projectSelectionViewer.setInput(getModelProjects()); + Collection modelProjects = getModelProjects(); + projectSelectionViewer.setInput(modelProjects); projectSelectionViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { - if (event.getSelection() instanceof IStructuredSelection) { IStructuredSelection iSelection = (IStructuredSelection) event.getSelection(); IModelProject project = (IModelProject) iSelection.getFirstElement(); @@ -136,9 +136,9 @@ public void selectionChanged(SelectionChangedEvent event) { infoModelTreeViewer = new InfomodelTreeViewer(modelPanel, this); getSite().setSelectionProvider(infoModelTreeViewer.treeViewer); - - if (!getModelProjects().isEmpty()) { - setSelectedProject(getModelProjects().iterator().next()); + + if (!modelProjects.isEmpty()) { + setSelectedProject(modelProjects.iterator().next()); } } @@ -168,6 +168,12 @@ public void refresh() { populate(project); } } + + public void refreshCurrent() { + // setting the selected project will call populate on that project which in turn + // will refresh it + setSelectedProject(selectedProject); + } private ComboViewer createProjectSelectionViewer(final Composite container, String labelStr) { Button newProjectButton = new Button(container, SWT.NONE);