Skip to content

Commit

Permalink
Fixes #339 - Adding Modeldependency empties model.
Browse files Browse the repository at this point in the history
Signed-off-by: Erle Czar Mantos <[email protected]>
  • Loading branch information
Erle Czar Mantos committed Jul 28, 2016
1 parent 5ba006c commit 85d8d01
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
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;
import org.eclipse.swt.dnd.TransferData;
import org.eclipse.vorto.core.ui.model.IModelElement;
import org.eclipse.vorto.core.ui.model.IModelProject;
import org.eclipse.vorto.perspective.view.ILocalModelWorkspace;
import org.eclipse.vorto.perspective.view.ModelProjectTreeViewer;

/**
Expand All @@ -36,13 +37,16 @@

// -erle- : This needs to be refactored.
public class ModelDropListener extends ViewerDropAdapter {

private ILocalModelWorkspace localModelBrowser;

private Class<?> allowedTarget;

private Collection<DropSourceValidatorAndAction> dropActors = new ArrayList<DropSourceValidatorAndAction>();

public ModelDropListener(Viewer viewer) {
super(viewer);
public ModelDropListener(Viewer viewer, ILocalModelWorkspace localModelBrowser) {
super(Objects.requireNonNull(viewer));
this.localModelBrowser = Objects.requireNonNull(localModelBrowser);
}

public ModelDropListener setAllowedTarget(Class<?> allowedTarget) {
Expand Down Expand Up @@ -79,7 +83,6 @@ public boolean performDrop(Object data) {
if (targetModelElement != null) {
viewer.expandToLevel(targetModelElement, 1);
}

return true;
}

Expand All @@ -99,15 +102,14 @@ private IModelElement findTarget(IModelElement target, Collection<IModelElement>

private Object getTarget() {
Object target = this.getCurrentTarget();
if (target == null) {
Viewer viewer = this.getViewer();
if (viewer instanceof ModelProjectTreeViewer) {
target = ((ModelProjectTreeViewer) viewer).getLocalModelWorkspace().getProjectBrowser()
.getSelectedProject();
}

if (target instanceof IModelElement) {
// Get the latest version of this IModelElement
IModelProject project = localModelBrowser.getProjectBrowser().getSelectedProject();
return project.getModelElementById(((IModelElement) target).getId());
}

return target;
throw new RuntimeException("Target is not an IModelElement");
}

public boolean validateDrop(Object target, int operation, TransferData transferType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
import org.eclipse.vorto.perspective.dnd.dropvalidator.DatatypeValidator;
import org.eclipse.vorto.perspective.dnd.dropvalidator.TargetClassModelTypeValidator;
import org.eclipse.vorto.perspective.dnd.dropvalidator.TargetClassSourceClassValidator;
import org.eclipse.vorto.perspective.view.ILocalModelWorkspace;

public class ModelDropListenerFactory {

public static DropTargetListener datatypeViewPartDropListener(Viewer viewer) {
return new ModelDropListener(viewer)
public static DropTargetListener datatypeViewPartDropListener(Viewer viewer, ILocalModelWorkspace localModelBrowser) {
return new ModelDropListener(viewer, localModelBrowser)
.addDropAction(
new DatatypeValidator(
DatatypeModelElement.class,
Expand All @@ -49,8 +50,8 @@ public static DropTargetListener datatypeViewPartDropListener(Viewer viewer) {
new AddSharedReferenceDropAction(ModelResource.class));
}

public static DropTargetListener functionblockViewPartDropListener(Viewer viewer) {
return new ModelDropListener(viewer)
public static DropTargetListener functionblockViewPartDropListener(Viewer viewer, ILocalModelWorkspace localModelBrowser) {
return new ModelDropListener(viewer, localModelBrowser)
.addDropAction(
new TargetClassSourceClassValidator(
FunctionblockModelElement.class,
Expand All @@ -72,8 +73,8 @@ public static DropTargetListener functionblockViewPartDropListener(Viewer viewer
new AddSharedReferenceDropAction(ModelResource.class));
}

public static DropTargetListener infomodelViewPartDropListener(Viewer viewer) {
return new ModelDropListener(viewer)
public static DropTargetListener infomodelViewPartDropListener(Viewer viewer, ILocalModelWorkspace localModelBrowser) {
return new ModelDropListener(viewer, localModelBrowser)
.addDropAction(
new TargetClassSourceClassValidator(
InformationModelElement.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected void init() {
Transfer[] transferTypes = new Transfer[] { LocalSelectionTransfer.getTransfer() };
treeViewer.addDragSupport(operations, transferTypes, new ModelDragListener(treeViewer));
treeViewer.addDropSupport(operations, transferTypes,
ModelDropListenerFactory.datatypeViewPartDropListener(treeViewer));
ModelDropListenerFactory.datatypeViewPartDropListener(treeViewer, localModelWorkspace));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void init() {
Transfer[] transferTypes = new Transfer[] { LocalSelectionTransfer.getTransfer() };
treeViewer.addDragSupport(operations, transferTypes, new ModelDragListener(treeViewer));
treeViewer.addDropSupport(operations, transferTypes,
ModelDropListenerFactory.functionblockViewPartDropListener(treeViewer));
ModelDropListenerFactory.functionblockViewPartDropListener(treeViewer, localModelWorkspace));
}

protected void initContextMenu() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void init() {
Transfer[] transferTypes = new Transfer[] { LocalSelectionTransfer.getTransfer() };

treeViewer.addDropSupport(operations, transferTypes,
ModelDropListenerFactory.infomodelViewPartDropListener(treeViewer));
ModelDropListenerFactory.infomodelViewPartDropListener(treeViewer, localModelWorkspace));
}

protected void initContextMenu() {
Expand Down

0 comments on commit 85d8d01

Please sign in to comment.