Skip to content

Commit

Permalink
Fix Drag n Drop in the teiid and server views
Browse files Browse the repository at this point in the history
* plugin.xml
 * Relocates instanceof checks to a definition since it is used more than
   once
 * The drop assistant will only be picked up by the navigator if the content's
   possibleChildren includes the type of the object being dragged hence the
   inclusion of the IFile.

* TeiidServerDropAdapterAssistant
 * Appears to transfer between navigators using LocalSelectionTransfer so
   this is supported as well as the original IResource[]

* SelectionUtilities
 * Fixes generics

* ModelExporerResourceNavigator
 * Fixes deprecation by replacing class LocalSelectionTransfer

* DeployVdbAction
 * Test the given TeiidServer rather than the default server. Since we have
   the given server and we use it, why test any others?
  • Loading branch information
Paul Richardson committed Nov 12, 2012
1 parent 3c15915 commit 3275c73
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 126 deletions.
90 changes: 51 additions & 39 deletions plugins/org.teiid.designer.dqp.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -232,25 +232,19 @@
</instanceof>
</triggerPoints>
<possibleChildren>
<instanceof
value="org.teiid.designer.runtime.ui.views.content.ITeiidResourceNode">
</instanceof>
<instanceof
value="org.teiid.designer.runtime.ui.views.content.TeiidServerContainerNode">
</instanceof>
<instanceof
value="org.teiid.designer.runtime.ui.views.content.AbstractTeiidFolder">
</instanceof>
<instanceof
value="org.teiid.designer.runtime.ui.views.content.TeiidDataNode">
</instanceof>
<instanceof
value="org.teiid.designer.runtime.ui.views.content.TeiidEmptyNode">
</instanceof>
<instanceof
value="org.teiid.designer.runtime.ui.views.content.TeiidErrorNode">
</instanceof>
<reference
definitionId="org.teiid.designer.dqp.ui.nodeDefinition">
</reference>
</possibleChildren>
<dropAssistant
class="org.teiid.designer.runtime.ui.views.TeiidServerDropAdapterAssistant"
id="org.teiid.designer.dqp.ui.server.view.dropAdapter">
<possibleDropTargets>
<reference
definitionId="org.teiid.designer.dqp.ui.nodeDefinition">
</reference>
</possibleDropTargets>
</dropAssistant>
</navigatorContent>
<navigatorContent
activeByDefault="true"
Expand All @@ -266,29 +260,18 @@
</instanceof>
</triggerPoints>
<possibleChildren>
<instanceof
value="org.teiid.designer.runtime.ui.views.content.ITeiidResourceNode">
</instanceof>
<instanceof
value="org.teiid.designer.runtime.ui.views.content.TeiidServerContainerNode">
</instanceof>
<instanceof
value="org.teiid.designer.runtime.ui.views.content.AbstractTeiidFolder">
</instanceof>
<instanceof
value="org.teiid.designer.runtime.ui.views.content.TeiidDataNode">
</instanceof>
<instanceof
value="org.teiid.designer.runtime.ui.views.content.TeiidEmptyNode">
</instanceof>
<instanceof
value="org.teiid.designer.runtime.ui.views.content.TeiidErrorNode">
</instanceof>
<reference
definitionId="org.teiid.designer.dqp.ui.nodeDefinition">
</reference>
</possibleChildren>
<dropAssistant
class="org.teiid.designer.runtime.ui.views.TeiidViewDropAdapterAssistant"
id="org.teiid.designer.runtime.ui.views.Teiid.dnd">
<possibleDropTargets></possibleDropTargets>
class="org.teiid.designer.runtime.ui.views.TeiidServerDropAdapterAssistant"
id="org.teiid.designer.dqp.ui.teiid.view.dropAdapter">
<possibleDropTargets>
<reference
definitionId="org.teiid.designer.dqp.ui.nodeDefinition">
</reference>
</possibleDropTargets>
</dropAssistant>
</navigatorContent>
<actionProvider
Expand Down Expand Up @@ -384,4 +367,33 @@
</adapter>
</factory>
</extension>
<extension
point="org.eclipse.core.expressions.definitions">
<definition
id="org.teiid.designer.dqp.ui.nodeDefinition">
<or>
<instanceof
value="org.eclipse.core.resources.IFile">
</instanceof>
<instanceof
value="org.teiid.designer.runtime.ui.views.content.ITeiidResourceNode">
</instanceof>
<instanceof
value="org.teiid.designer.runtime.ui.views.content.TeiidServerContainerNode">
</instanceof>
<instanceof
value="org.teiid.designer.runtime.ui.views.content.AbstractTeiidFolder">
</instanceof>
<instanceof
value="org.teiid.designer.runtime.ui.views.content.TeiidDataNode">
</instanceof>
<instanceof
value="org.teiid.designer.runtime.ui.views.content.TeiidEmptyNode">
</instanceof>
<instanceof
value="org.teiid.designer.runtime.ui.views.content.TeiidErrorNode">
</instanceof>
</or>
</definition>
</extension>
</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.teiid.designer.runtime.TeiidServerManager;
import org.teiid.designer.runtime.ui.DqpUiConstants;
import org.teiid.designer.runtime.ui.DqpUiPlugin;
import org.teiid.designer.runtime.ui.server.RuntimeAssistant;
import org.teiid.designer.runtime.ui.vdb.DeployVdbDialog;
import org.teiid.designer.runtime.ui.vdb.VdbDeployer;
import org.teiid.designer.runtime.ui.vdb.VdbRequiresSaveChecker;
Expand Down Expand Up @@ -205,7 +204,7 @@ public static VDB deployVdb(TeiidServer teiidServer, final Object vdbOrVdbFile,
}

// make sure there is a Teiid connection
if (!RuntimeAssistant.ensureServerConnection(shell, UTIL.getString(I18N_PREFIX + "noTeiidInstanceMsg"))) { //$NON-NLS-1$
if (! teiidServer.isConnected()) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,30 @@
*/
package org.teiid.designer.runtime.ui.views;

import java.util.List;
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.jface.viewers.ISelection;
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.runtime.ui.server.RuntimeAssistant;
import org.teiid.designer.ui.common.eventsupport.SelectionUtilities;
import org.teiid.designer.ui.viewsupport.ModelIdentifier;

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

/**
* The current transfer data, or <code>null</code> if none.
Expand All @@ -39,14 +42,16 @@ public class TeiidViewDropAdapterAssistant extends CommonDropAdapterAssistant {
@Override
public IStatus validateDrop(Object target, int operation, TransferData transferType) {
currentTransfer = transferType;
if (target instanceof TeiidTranslator && currentTransfer != null
&& ResourceTransfer.getInstance().isSupportedType(currentTransfer)) {

if (RuntimeAssistant.adapt(target, TeiidTranslator.class) != null && currentTransfer != null
&& 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)) {
} else if (RuntimeAssistant.adapt(target, TeiidServer.class) != null && currentTransfer != null
&& isSupportedType(currentTransfer)) {
// plugin cannot be loaded without the plugin data
theTargetServer = (TeiidServer) target;
theTargetServer = RuntimeAssistant.adapt(target, TeiidServer.class);

return Status.OK_STATUS;
}

Expand All @@ -57,29 +62,50 @@ public IStatus validateDrop(Object target, int operation, TransferData transferT
@Override
public IStatus handleDrop(CommonDropAdapter aDropAdapter, DropTargetEvent aDropTargetEvent, Object aTarget) {
Object theData = aDropTargetEvent.data;
if (! (theData instanceof IResource[]))

if (theData instanceof ISelection) {
List<Object> selectedObjects = SelectionUtilities.getSelectedObjects((ISelection) theData);
for (Object o : selectedObjects) {
if (o instanceof IResource) {
IStatus status = handleResource((IResource) o);
if (status != Status.OK_STATUS)
return status;
}
}
}
else if (theData instanceof IResource[]) {
IResource[] resources = (IResource[])theData;
for( IResource resource : resources ) {
IStatus status = handleResource(resource);
if (status != Status.OK_STATUS)
return status;
}
}
else {
return Status.CANCEL_STATUS;
}

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

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,
private IStatus handleResource(IResource resource) {
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;

if ("vdb".equals(theFile.getFileExtension())) { //$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));
}
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ public static Object getSelectedObject(ISelection theSelection) {
* @param theSelection the selection whose selected <code>Object</code>s are being requested
* @return the selected <code>Object</code>s or an empty <code>List</code>
*/
public static List getSelectedObjects(ISelection theSelection) {
List result = null;
public static List<Object> getSelectedObjects(ISelection theSelection) {
List<Object> result = null;

if ((theSelection != null) && !theSelection.isEmpty()) {
if (theSelection instanceof IStructuredSelection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.AbstractTreeViewer;
import org.eclipse.jface.viewers.DecoratingLabelProvider;
import org.eclipse.jface.viewers.DoubleClickEvent;
Expand Down Expand Up @@ -77,7 +78,6 @@
import org.eclipse.ui.part.PluginTransfer;
import org.eclipse.ui.part.ResourceTransfer;
import org.eclipse.ui.part.ShowInContext;
import org.eclipse.ui.views.navigator.LocalSelectionTransfer;
import org.eclipse.ui.views.navigator.NavigatorDropAdapter;
import org.eclipse.ui.views.navigator.ResourceNavigator;
import org.eclipse.ui.views.properties.IPropertySheetPage;
Expand Down Expand Up @@ -1013,7 +1013,7 @@ protected void initDragAndDrop() {
// code copied from superclass. only change is to the drag adapter
TreeViewer viewer = getTreeViewer();
int ops = DND.DROP_COPY | DND.DROP_MOVE;
Transfer[] transfers = new Transfer[] {LocalSelectionTransfer.getInstance(), ResourceTransfer.getInstance(),
Transfer[] transfers = new Transfer[] {LocalSelectionTransfer.getTransfer(), ResourceTransfer.getInstance(),
FileTransfer.getInstance(), PluginTransfer.getInstance(), EObjectTransfer.getInstance()};

// drop support
Expand Down

0 comments on commit 3275c73

Please sign in to comment.