Skip to content

Commit

Permalink
TEIIDDES-1459: Migrate the DnD to CommonNavigator framework
Browse files Browse the repository at this point in the history
* TeiidView
 * Rather than initialising the DnD adapter manually, uses the DnDAssistant
   plugin extension to the CommonNavigator framework.
  • Loading branch information
Paul Richardson committed Sep 3, 2012
1 parent 8e50ed3 commit fbeb1e2
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 129 deletions.
5 changes: 5 additions & 0 deletions plugins/org.teiid.designer.dqp.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@
value="org.teiid.designer.runtime.ui.views.content.TeiidServerContainerNode">
</instanceof>
</triggerPoints>
<dropAssistant
class="org.teiid.designer.runtime.ui.views.TeiidViewDropAdapterAssistant"
id="org.teiid.designer.runtime.ui.views.Teiid.dnd">
<possibleDropTargets></possibleDropTargets>
</dropAssistant>
</navigatorContent>
<actionProvider
class="org.teiid.designer.runtime.ui.views.TeiidServerActionProvider"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionEvent;
Expand All @@ -39,7 +37,6 @@
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.navigator.CommonNavigator;
import org.eclipse.ui.navigator.CommonViewer;
import org.eclipse.ui.part.ResourceTransfer;
import org.eclipse.ui.views.properties.IPropertySheetPage;
import org.eclipse.ui.views.properties.IPropertySourceProvider;
import org.eclipse.ui.views.properties.PropertySheetPage;
Expand Down Expand Up @@ -244,8 +241,6 @@ public void widgetDefaultSelected(SelectionEvent e) {

viewer = getCommonViewer();
GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getControl());

// initDragAndDrop();

hookToolTips();

Expand Down Expand Up @@ -493,21 +488,6 @@ public void handleEvent( Event event ) {
viewer.getTree().addListener(SWT.MouseHover, treeListener);
}

/**
* @see org.eclipse.ui.views.navigator.ResourceNavigator#initDragAndDrop()
*/
private void initDragAndDrop() {
// code copied from superclass. only change is to the drag adapter
int ops = DND.DROP_COPY | DND.DROP_MOVE;
Transfer[] transfers = new Transfer[] {ResourceTransfer.getInstance()};

// drop support
TeiidViewDropAdapter adapter = new TeiidViewDropAdapter(this.viewer);
adapter.setFeedbackEnabled(false);

viewer.addDropSupport(ops | DND.DROP_DEFAULT, transfers, adapter);
}

private void initKeyListener() {

// create the adapter
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* JBoss, Home of Professional Open Source.
*
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
*
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
*/
package org.teiid.designer.runtime.ui.views;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.TransferData;
import org.eclipse.ui.navigator.CommonDropAdapter;
import org.eclipse.ui.navigator.CommonDropAdapterAssistant;
import org.eclipse.ui.part.ResourceTransfer;
import org.teiid.designer.core.ModelerCore;
import org.teiid.designer.core.workspace.ModelResource;
import org.teiid.designer.runtime.TeiidServer;
import org.teiid.designer.runtime.TeiidTranslator;
import org.teiid.designer.runtime.ui.DqpUiConstants;
import org.teiid.designer.runtime.ui.actions.DeployVdbAction;
import org.teiid.designer.ui.viewsupport.ModelIdentifier;

/**
* @since 8.0
*/
public class TeiidViewDropAdapterAssistant extends CommonDropAdapterAssistant {

/**
* The current transfer data, or <code>null</code> if none.
*/
private TransferData currentTransfer;

private TeiidServer theTargetServer;

@Override
public IStatus validateDrop(Object target, int operation, TransferData transferType) {
currentTransfer = transferType;
if (target instanceof TeiidTranslator && currentTransfer != null
&& ResourceTransfer.getInstance().isSupportedType(currentTransfer)) {
// plugin cannot be loaded without the plugin data
return Status.OK_STATUS;
} else if (target instanceof TeiidServer && currentTransfer != null
&& ResourceTransfer.getInstance().isSupportedType(currentTransfer)) {
// plugin cannot be loaded without the plugin data
theTargetServer = (TeiidServer) target;
return Status.OK_STATUS;
}

theTargetServer = null;
return Status.CANCEL_STATUS;
}

@Override
public IStatus handleDrop(CommonDropAdapter aDropAdapter, DropTargetEvent aDropTargetEvent, Object aTarget) {
Object theData = aDropTargetEvent.data;
if (! (theData instanceof IResource[]))
return Status.CANCEL_STATUS;

IResource[] resources = (IResource[])theData;
for( IResource resource : resources ) {
ModelResource mr = ModelerCore.getModelWorkspace().findModelResource(resource);

if (mr != null && ModelIdentifier.isPhysicalModelType(mr)) {
currentTransfer = null;
return Status.OK_STATUS;
} else if (resource instanceof IFile) {
IFile theFile = (IFile)resource;
String extension = theFile.getFileExtension();
if (extension != null && extension.equals("vdb")) { //$NON-NLS-1$
try {
DeployVdbAction.deployVdb(theTargetServer, theFile);
} catch (Exception e) {
DqpUiConstants.UTIL.log(IStatus.ERROR,
e,
DqpUiConstants.UTIL.getString( "TeiidViewDropAdapter.problemDeployingVdbToServer", //$NON-NLS-1$
theFile.getName(),
theTargetServer));
}
}
}
}

return Status.CANCEL_STATUS;
}

}

0 comments on commit fbeb1e2

Please sign in to comment.