List of usage examples for org.eclipse.jface.util LocalSelectionTransfer getSelection
public ISelection getSelection()
From source file:ca.mcgill.cs.swevo.qualyzer.providers.TreeDropListener.java
License:Open Source License
/** * Verifies that the drop is allowed by checking for cycles and duplicates. *//* ww w.j a v a2 s . c o m*/ @Override public boolean validateDrop(Object target, int operation, TransferData transferType) { LocalSelectionTransfer sel = LocalSelectionTransfer.getTransfer(); IStructuredSelection selection = (IStructuredSelection) sel.getSelection(); Node nTarget = (Node) target; if (nTarget == null) { nTarget = (Node) fViewer.getInput(); } String data = (String) selection.getFirstElement(); String[] values = data.split(SPLIT); Long id = null; boolean valid = true; if (nTarget != null) { if (values.length == TABLE_DATA_SIZE) { id = Long.parseLong(values[1]); //if(hardCycleExists(nTarget, id, fPage.getTreeModel())) if (containsCycle(id, nTarget)) { valid = false; } } else if (values.length == TREE_DATA_SIZE) { id = Long.parseLong(values[0]); Node node = findNode(values[1], id); if (depthFirstContainsCycle(node, nTarget)) { valid = false; } } Node child = nTarget.getChild(id); if (child != null) { valid = false; } return valid && TextTransfer.getInstance().isSupportedType(transferType); } return false; }
From source file:com.bdaum.zoom.ui.internal.views.AbstractPresentationView.java
License:Open Source License
protected void addDropListener(final Control control) { final int ops = DND.DROP_MOVE | DND.DROP_COPY; final DropTarget target = new DropTarget(control, ops); final LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer(); target.setTransfer(new Transfer[] { transfer }); target.addDropListener(new EffectDropTargetListener(control) { @Override//w w w .j av a 2 s. c o m public void dragEnter(DropTargetEvent event) { int detail = event.detail; event.detail = DND.DROP_NONE; if (!dbIsReadonly()) for (int i = 0; i < event.dataTypes.length; i++) if (transfer.isSupportedType(event.dataTypes[i])) { event.currentDataType = event.dataTypes[i]; event.detail = (detail & ops) == 0 ? DND.DROP_NONE : DND.DROP_COPY; break; } super.dragEnter(event); } @Override public void dragOver(DropTargetEvent event) { super.dragOver(event); if ((event.detail & DND.DROP_MOVE) != 0) { org.eclipse.swt.graphics.Point pc = canvas.toControl(event.x, event.y); if (findExhibit(toLocal(pc)) == null) event.detail = DND.DROP_COPY; } } public void dragOperationChanged(DropTargetEvent event) { int detail = event.detail; event.detail = DND.DROP_NONE; if (transfer.isSupportedType(event.currentDataType) && !dbIsReadonly()) event.detail = (detail & ops) == 0 ? DND.DROP_NONE : (detail & DND.DROP_COPY) == 0 ? DND.DROP_COPY : DND.DROP_MOVE; } public void drop(DropTargetEvent event) { if (transfer.isSupportedType(event.currentDataType) && !dbIsReadonly()) { ISelection selection = transfer.getSelection(); if (selection instanceof AssetSelection) { org.eclipse.swt.graphics.Point pc = canvas.toControl(event.x, event.y); dropAssets(selection, pc, toLocal(pc), (event.detail & DND.DROP_MOVE) != 0); } } } private Point2D toLocal(org.eclipse.swt.graphics.Point pc) { PCamera camera = canvas.getCamera(); Point2D globalToLocal = new Point(pc.x, pc.y); camera.globalToLocal(globalToLocal); camera.localToView(globalToLocal); surface.parentToLocal(globalToLocal); return globalToLocal; } }); }
From source file:de.byteholder.geoclipse.mapprovider.ProfileDropAdapter.java
License:Open Source License
@Override public boolean validateDrop(final Object target, final int operation, final TransferData transferType) { // disable auto expand for tree items which have children setExpandEnabled(false);//from ww w . jav a2 s . c om final LocalSelectionTransfer localTransfer = LocalSelectionTransfer.getTransfer(); if (localTransfer.isSupportedType(transferType) == false) { return false; } final ISelection selection = localTransfer.getSelection(); if ((selection instanceof StructuredSelection) == false) { return false; } final Object draggedItem = ((StructuredSelection) selection).getFirstElement(); // don't drop on itself if (target == draggedItem) { return false; } // check drop location final int location = getCurrentLocation(); if ((location == LOCATION_AFTER || location == LOCATION_BEFORE) == false) { return false; } if (draggedItem instanceof TVIMapProvider && target instanceof TVIMapProvider) { // support the reorder of map providers return true; } else if (draggedItem instanceof TVIWmsLayer && target instanceof TVIWmsLayer) { // support the reorder of wms layer // check if the layers have the same parent final TreeViewerItem draggedParent = ((TVIWmsLayer) draggedItem).getParentItem(); final TreeViewerItem targetParent = ((TVIWmsLayer) target).getParentItem(); if (draggedParent == targetParent) { return true; } } return false; }
From source file:net.tourbook.common.util.DialogModifyColumns.java
License:Open Source License
private void createUI_72_ColumnsViewer(final Composite parent) { final TableColumnLayout tableLayout = new TableColumnLayout(); final Composite layoutContainer = new Composite(parent, SWT.NONE); layoutContainer.setLayout(tableLayout); GridDataFactory.fillDefaults().grab(true, true).applyTo(layoutContainer); /*/*from w ww. j a v a 2 s.c om*/ * create table */ final Table table = new Table(layoutContainer, SWT.CHECK | SWT.FULL_SELECTION | SWT.BORDER); table.setLayout(new TableLayout()); table.setHeaderVisible(true); table.setLinesVisible(false); _columnViewer = new CheckboxTableViewer(table); defineAllColumns(tableLayout); reorderColumns(table); _columnViewer.setContentProvider(new IStructuredContentProvider() { @Override public void dispose() { } @Override public Object[] getElements(final Object inputElement) { return _columnViewerModel.toArray(); } @Override public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) { } }); _columnViewer.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(final DoubleClickEvent event) { final Object firstElement = ((IStructuredSelection) _columnViewer.getSelection()).getFirstElement(); if (firstElement != null) { // check/uncheck current item _columnViewer.setChecked(firstElement, !_columnViewer.getChecked(firstElement)); } } }); _columnViewer.addCheckStateListener(new ICheckStateListener() { @Override public void checkStateChanged(final CheckStateChangedEvent event) { final ColumnDefinition colDef = (ColumnDefinition) event.getElement(); if (colDef.canModifyVisibility()) { // keep the checked status colDef.setIsColumnDisplayed(event.getChecked()); // select the checked item _columnViewer.setSelection(new StructuredSelection(colDef)); } else { // column can't be unchecked _columnViewer.setChecked(colDef, true); } // save columns saveState_CurrentProfileColumns(); } }); _columnViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(final SelectionChangedEvent event) { enableUpDownActions(); } }); /* * set drag adapter */ _columnViewer.addDragSupport(DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new DragSourceListener() { @Override public void dragFinished(final DragSourceEvent event) { final LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer(); if (event.doit == false) { return; } transfer.setSelection(null); transfer.setSelectionSetTime(0); } @Override public void dragSetData(final DragSourceEvent event) { // data are set in LocalSelectionTransfer } @Override public void dragStart(final DragSourceEvent event) { final LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer(); final ISelection selection = _columnViewer.getSelection(); _dndCheckedElements = _columnViewer.getCheckedElements(); transfer.setSelection(selection); transfer.setSelectionSetTime(_dndDragStartViewerLeft = event.time & 0xFFFFFFFFL); event.doit = !selection.isEmpty(); } }); /* * set drop adapter */ final ViewerDropAdapter viewerDropAdapter = new ViewerDropAdapter(_columnViewer) { private Widget _dragOverItem; @Override public void dragOver(final DropTargetEvent dropEvent) { // keep table item _dragOverItem = dropEvent.item; super.dragOver(dropEvent); } @Override public boolean performDrop(final Object data) { if (data instanceof StructuredSelection) { final StructuredSelection selection = (StructuredSelection) data; if (selection.getFirstElement() instanceof ColumnDefinition) { final ColumnDefinition colDef = (ColumnDefinition) selection.getFirstElement(); final int location = getCurrentLocation(); final Table filterTable = _columnViewer.getTable(); /* * check if drag was startet from this item, remove the item before the new * item is inserted */ if (LocalSelectionTransfer.getTransfer().getSelectionSetTime() == _dndDragStartViewerLeft) { _columnViewer.remove(colDef); } int filterIndex; if (_dragOverItem == null) { _columnViewer.add(colDef); filterIndex = filterTable.getItemCount() - 1; } else { // get index of the target in the table filterIndex = filterTable.indexOf((TableItem) _dragOverItem); if (filterIndex == -1) { return false; } if (location == LOCATION_BEFORE) { _columnViewer.insert(colDef, filterIndex); } else if (location == LOCATION_AFTER || location == LOCATION_ON) { _columnViewer.insert(colDef, ++filterIndex); } } // reselect filter item _columnViewer.setSelection(new StructuredSelection(colDef)); // set focus to selection filterTable.setSelection(filterIndex); filterTable.setFocus(); // recheck items _columnViewer.setCheckedElements(_dndCheckedElements); enableUpDownActions(); return true; } } return false; } @Override public boolean validateDrop(final Object target, final int operation, final TransferData transferType) { final LocalSelectionTransfer transferData = LocalSelectionTransfer.getTransfer(); // check if dragged item is the target item final ISelection selection = transferData.getSelection(); if (selection instanceof StructuredSelection) { final Object dragFilter = ((StructuredSelection) selection).getFirstElement(); if (target == dragFilter) { return false; } } if (transferData.isSupportedType(transferType) == false) { return false; } // check if target is between two items if (getCurrentLocation() == LOCATION_ON) { return false; } return true; } }; _columnViewer.addDropSupport(DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer() }, viewerDropAdapter); }
From source file:net.tourbook.map2.view.DialogModifyMapProvider.java
License:Open Source License
private void createUI10MapProviderList(final Composite parent) { final PixelConverter pc = new PixelConverter(parent); _checkboxViewer = CheckboxTableViewer.newCheckList(parent, SWT.SINGLE | SWT.TOP | SWT.BORDER); final Table table = _checkboxViewer.getTable(); GridDataFactory.swtDefaults()// .grab(true, true).hint(SWT.DEFAULT, pc.convertHeightInCharsToPixels(10)).align(SWT.FILL, SWT.FILL) .applyTo(table);//from w w w . ja va 2 s. c om _checkboxViewer.setContentProvider(new IStructuredContentProvider() { public void dispose() { } public Object[] getElements(final Object inputElement) { return _allMp.toArray(); } public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) { } }); _checkboxViewer.setLabelProvider(new LabelProvider() { @Override public String getText(final Object element) { return ((MP) element).getName(); } }); _checkboxViewer.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(final CheckStateChangedEvent event) { // keep the checked status final MP item = (MP) event.getElement(); item.setCanBeToggled(event.getChecked()); // select the checked item _checkboxViewer.setSelection(new StructuredSelection(item)); // // validateTab(); } }); _checkboxViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(final SelectionChangedEvent event) { enableUpDownButtons(); } }); /* * set drag adapter */ _checkboxViewer.addDragSupport(DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new DragSourceListener() { public void dragFinished(final DragSourceEvent event) { final LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer(); if (event.doit == false) { return; } transfer.setSelection(null); transfer.setSelectionSetTime(0); } public void dragSetData(final DragSourceEvent event) { // data are set in LocalSelectionTransfer } public void dragStart(final DragSourceEvent event) { final LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer(); final ISelection selection = _checkboxViewer.getSelection(); _dndCheckedElements = _checkboxViewer.getCheckedElements(); transfer.setSelection(selection); transfer.setSelectionSetTime(_dndDragStartViewerLeft = event.time & 0xFFFFFFFFL); event.doit = !selection.isEmpty(); } }); /* * set drop adapter */ final ViewerDropAdapter viewerDropAdapter = new ViewerDropAdapter(_checkboxViewer) { private Widget _dragOverItem; @Override public void dragOver(final DropTargetEvent dropEvent) { // keep table item _dragOverItem = dropEvent.item; super.dragOver(dropEvent); } @Override public boolean performDrop(final Object data) { if (data instanceof StructuredSelection) { final StructuredSelection selection = (StructuredSelection) data; if (selection.getFirstElement() instanceof MP) { final MP mp = (MP) selection.getFirstElement(); final int location = getCurrentLocation(); final Table filterTable = _checkboxViewer.getTable(); /* * check if drag was startet from this item, remove the item before the new * item is inserted */ if (LocalSelectionTransfer.getTransfer().getSelectionSetTime() == _dndDragStartViewerLeft) { _checkboxViewer.remove(mp); } int filterIndex; if (_dragOverItem == null) { _checkboxViewer.add(mp); filterIndex = filterTable.getItemCount() - 1; } else { // get index of the target in the table filterIndex = filterTable.indexOf((TableItem) _dragOverItem); if (filterIndex == -1) { return false; } if (location == LOCATION_BEFORE) { _checkboxViewer.insert(mp, filterIndex); } else if (location == LOCATION_AFTER || location == LOCATION_ON) { _checkboxViewer.insert(mp, ++filterIndex); } } // reselect filter item _checkboxViewer.setSelection(new StructuredSelection(mp)); // set focus to selection filterTable.setSelection(filterIndex); filterTable.setFocus(); // recheck items _checkboxViewer.setCheckedElements(_dndCheckedElements); enableUpDownButtons(); return true; } } return false; } @Override public boolean validateDrop(final Object target, final int operation, final TransferData transferType) { final LocalSelectionTransfer transferData = LocalSelectionTransfer.getTransfer(); // check if dragged item is the target item final ISelection selection = transferData.getSelection(); if (selection instanceof StructuredSelection) { final Object dragFilter = ((StructuredSelection) selection).getFirstElement(); if (target == dragFilter) { return false; } } if (transferData.isSupportedType(transferType) == false) { return false; } // check if target is between two items if (getCurrentLocation() == LOCATION_ON) { return false; } return true; } }; _checkboxViewer.addDropSupport(DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer() }, viewerDropAdapter); }
From source file:net.tourbook.preferences.TagDropAdapter.java
License:Open Source License
@Override public boolean validateDrop(final Object target, final int operation, final TransferData transferType) { final LocalSelectionTransfer localTransfer = LocalSelectionTransfer.getTransfer(); if (localTransfer.isSupportedType(transferType) == false) { return false; }/* w w w .j av a 2s. c om*/ final ISelection selection = localTransfer.getSelection(); if (selection instanceof StructuredSelection) { final Object draggedItem = ((StructuredSelection) selection).getFirstElement(); if (target == draggedItem) { // don't drop on itself return false; } else { if (draggedItem instanceof TVIPrefTagCategory) { if (target instanceof TVIPrefTagCategory) { /* * check if a dragged category item is dropped on one of it's children, this * is not allowed */ final TVIPrefTagCategory itemDraggedCategory = (TVIPrefTagCategory) draggedItem; final TVIPrefTagCategory itemTargetCategory = (TVIPrefTagCategory) target; final long targetCategoryId = itemTargetCategory.getTourTagCategory().getCategoryId(); if (isDraggedIntoChildren(itemDraggedCategory, targetCategoryId)) { return false; } } else if (target instanceof TVIPrefTag) { return false; } } return true; } } return false; }
From source file:net.tourbook.util.DialogModifyColumns.java
License:Open Source License
private void createUI10ColumnsViewer(final Composite parent) { final TableColumnLayout tableLayout = new TableColumnLayout(); final Composite layoutContainer = new Composite(parent, SWT.NONE); layoutContainer.setLayout(tableLayout); GridDataFactory.fillDefaults().grab(true, true).applyTo(layoutContainer); /*/* w ww . ja v a 2 s. c o m*/ * create table */ final Table table = new Table(layoutContainer, SWT.CHECK | SWT.FULL_SELECTION | SWT.BORDER); table.setLayout(new TableLayout()); table.setHeaderVisible(true); table.setLinesVisible(true); _columnViewer = new CheckboxTableViewer(table); /* * create columns */ TableViewerColumn tvc; TableColumn tvcColumn; // column: label tvc = new TableViewerColumn(_columnViewer, SWT.LEAD); tvcColumn = tvc.getColumn(); tvcColumn.setText(Messages.ColumnModifyDialog_column_column); tvc.setLabelProvider(new CellLabelProvider() { @Override public void update(final ViewerCell cell) { final ColumnDefinition colDef = (ColumnDefinition) cell.getElement(); cell.setText(colDef.getColumnLabel()); // paint columns in a different color which can't be hidden if (colDef.canModifyVisibility() == false) { cell.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND)); } } }); tableLayout.setColumnData(tvcColumn, new ColumnWeightData(1, true)); // column: unit tvc = new TableViewerColumn(_columnViewer, SWT.LEAD); tvcColumn = tvc.getColumn(); tvcColumn.setText(Messages.ColumnModifyDialog_column_unit); tvc.setLabelProvider(new CellLabelProvider() { @Override public void update(final ViewerCell cell) { final ColumnDefinition colDef = (ColumnDefinition) cell.getElement(); cell.setText(colDef.getColumnUnit()); // paint columns in a different color which can't be hidden if (colDef.canModifyVisibility() == false) { cell.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND)); } } }); tableLayout.setColumnData(tvcColumn, new ColumnPixelData(_pc.convertWidthInCharsToPixels(13), true)); // column: width tvc = new TableViewerColumn(_columnViewer, SWT.TRAIL); tvcColumn = tvc.getColumn(); tvcColumn.setText(Messages.ColumnModifyDialog_column_width); tvc.setLabelProvider(new CellLabelProvider() { @Override public void update(final ViewerCell cell) { final ColumnDefinition colDef = (ColumnDefinition) cell.getElement(); cell.setText(Integer.toString(colDef.getColumnWidth())); // paint columns in a different color which can't be hidden if (colDef.canModifyVisibility() == false) { cell.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND)); } } }); tableLayout.setColumnData(tvcColumn, new ColumnPixelData(_pc.convertWidthInCharsToPixels(10), true)); _columnViewer.setContentProvider(new IStructuredContentProvider() { public void dispose() { } public Object[] getElements(final Object inputElement) { return _allColumnsInDialog.toArray(); } public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) { } }); _columnViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(final DoubleClickEvent event) { final Object firstElement = ((IStructuredSelection) _columnViewer.getSelection()).getFirstElement(); if (firstElement != null) { // check/uncheck current item _columnViewer.setChecked(firstElement, !_columnViewer.getChecked(firstElement)); } } }); _columnViewer.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(final CheckStateChangedEvent event) { final ColumnDefinition colDef = (ColumnDefinition) event.getElement(); if (colDef.canModifyVisibility()) { // keep the checked status colDef.setIsCheckedInDialog(event.getChecked()); // select the checked item _columnViewer.setSelection(new StructuredSelection(colDef)); } else { // column can't be unchecked _columnViewer.setChecked(colDef, true); } } }); _columnViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(final SelectionChangedEvent event) { enableUpDownButtons(); } }); /* * set drag adapter */ _columnViewer.addDragSupport(DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new DragSourceListener() { public void dragFinished(final DragSourceEvent event) { final LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer(); if (event.doit == false) { return; } transfer.setSelection(null); transfer.setSelectionSetTime(0); } public void dragSetData(final DragSourceEvent event) { // data are set in LocalSelectionTransfer } public void dragStart(final DragSourceEvent event) { final LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer(); final ISelection selection = _columnViewer.getSelection(); _dndCheckedElements = _columnViewer.getCheckedElements(); transfer.setSelection(selection); transfer.setSelectionSetTime(_dndDragStartViewerLeft = event.time & 0xFFFFFFFFL); event.doit = !selection.isEmpty(); } }); /* * set drop adapter */ final ViewerDropAdapter viewerDropAdapter = new ViewerDropAdapter(_columnViewer) { private Widget _dragOverItem; @Override public void dragOver(final DropTargetEvent dropEvent) { // keep table item _dragOverItem = dropEvent.item; super.dragOver(dropEvent); } @Override public boolean performDrop(final Object data) { if (data instanceof StructuredSelection) { final StructuredSelection selection = (StructuredSelection) data; if (selection.getFirstElement() instanceof ColumnDefinition) { final ColumnDefinition colDef = (ColumnDefinition) selection.getFirstElement(); final int location = getCurrentLocation(); final Table filterTable = _columnViewer.getTable(); /* * check if drag was startet from this item, remove the item before the new * item is inserted */ if (LocalSelectionTransfer.getTransfer().getSelectionSetTime() == _dndDragStartViewerLeft) { _columnViewer.remove(colDef); } int filterIndex; if (_dragOverItem == null) { _columnViewer.add(colDef); filterIndex = filterTable.getItemCount() - 1; } else { // get index of the target in the table filterIndex = filterTable.indexOf((TableItem) _dragOverItem); if (filterIndex == -1) { return false; } if (location == LOCATION_BEFORE) { _columnViewer.insert(colDef, filterIndex); } else if (location == LOCATION_AFTER || location == LOCATION_ON) { _columnViewer.insert(colDef, ++filterIndex); } } // reselect filter item _columnViewer.setSelection(new StructuredSelection(colDef)); // set focus to selection filterTable.setSelection(filterIndex); filterTable.setFocus(); // recheck items _columnViewer.setCheckedElements(_dndCheckedElements); enableUpDownButtons(); return true; } } return false; } @Override public boolean validateDrop(final Object target, final int operation, final TransferData transferType) { final LocalSelectionTransfer transferData = LocalSelectionTransfer.getTransfer(); // check if dragged item is the target item final ISelection selection = transferData.getSelection(); if (selection instanceof StructuredSelection) { final Object dragFilter = ((StructuredSelection) selection).getFirstElement(); if (target == dragFilter) { return false; } } if (transferData.isSupportedType(transferType) == false) { return false; } // check if target is between two items if (getCurrentLocation() == LOCATION_ON) { return false; } return true; } }; _columnViewer.addDropSupport(DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer() }, viewerDropAdapter); }
From source file:org.eclipse.tcf.te.launch.ui.viewer.dnd.CommonDnD.java
License:Open Source License
/** * Validate dropping when the elements being dragged are local selection. * * @param dropAdapter The common drop adapter. * @param target The target object./*from w ww . j av a 2 s . c om*/ * @param operation The DnD operation. * @param transferType The transfered data type. * * @return true if it is valid for dropping. */ public boolean isValidDnD(CommonDropAdapter dropAdapter, Object target, int operation, TransferData transferType) { boolean valid = false; int overrideOperation = -1; IStructuredSelection selection = null; if (LocalSelectionTransfer.getTransfer().isSupportedType(transferType)) { LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer(); selection = (IStructuredSelection) transfer.getSelection(); } if (selection == null) { return false; } boolean allow = true; target = translateObject(target); Iterator<?> iterator = selection.iterator(); boolean isCopy = (operation & DND.DROP_COPY) != 0; while (iterator.hasNext() && allow) { Object from = translateObject(iterator.next()); if (from instanceof LaunchNode) { LaunchNode fromNode = (LaunchNode) from; if (target instanceof LaunchNode) { // LaunchNode toNode = (LaunchNode)target; allow = false; } else if (target instanceof IModelNode) { IModelNode toContext = (IModelNode) target; allow &= internalValidate(fromNode, null, toContext, true, isCopy); } else if (target instanceof IResource) { IResource toResource = (IResource) target; allow &= internalValidate(fromNode, toResource, null, true, isCopy); } else if (target instanceof ICategory) { ICategory toCategory = (ICategory) target; overrideOperation = DND.DROP_LINK; allow &= fromNode.getLaunchConfiguration() != null && IUIConstants.ID_CAT_FAVORITES.equals(toCategory.getId()) && !Managers.getCategoryManager().belongsTo(toCategory.getId(), LaunchModel.getCategoryId(fromNode.getLaunchConfiguration())); } else if (target instanceof IRoot) { allow &= fromNode.getModel().getModelRoot() instanceof ICategory && fromNode.getLaunchConfiguration() != null && Managers.getCategoryManager().belongsTo( ((ICategory) fromNode.getModel().getModelRoot()).getId(), LaunchModel.getCategoryId(fromNode.getLaunchConfiguration())); } else { allow = false; } } else if (from instanceof IModelNode) { IModelNode fromContext = (IModelNode) from; if (target instanceof LaunchNode) { LaunchNode toNode = (LaunchNode) target; overrideOperation = DND.DROP_MOVE; allow &= internalValidate(toNode, null, fromContext, true, false); } else { allow = false; } } else if (from instanceof IResource) { IResource fromResource = (IResource) from; if (target instanceof LaunchNode) { LaunchNode toNode = (LaunchNode) target; allow &= internalValidate(toNode, fromResource, null, !isCopy, false); } else if (target instanceof IModelNode) { IModelNode toContext = (IModelNode) target; ILaunchSelection launchSel = new LaunchSelection(null, new ISelectionContext[] { new RemoteSelectionContext(toContext, new Object[] { toContext }, true), new ProjectSelectionContext(fromResource.getProject(), new Object[] { fromResource.getLocation() }, true) }); String[] typeIds = LaunchConfigTypeBindingsManager.getInstance() .getValidLaunchConfigTypes(launchSel); allow &= typeIds != null && typeIds.length > 0; } else { allow = false; } } else { allow = false; } } valid = allow; if (dropAdapter != null && valid) { if (overrideOperation > -1) { dropAdapter.overrideOperation(overrideOperation); } } return valid; }
From source file:org.eclipse.tcf.te.tcf.filesystem.ui.internal.dnd.CommonDnD.java
License:Open Source License
/** * Validate dropping when the elements being dragged are local selection. * * @param target The target object.//from w w w. j ava 2s . c o m * @param operation The DnD operation. * @param transferType The transfered data simulator. * @return true if it is valid for dropping. */ public boolean validateLocalSelectionDrop(Object target, int operation, TransferData transferType) { IFSTreeNode hovered = (IFSTreeNode) target; LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer(); IStructuredSelection selection = (IStructuredSelection) transfer.getSelection(); List<IFSTreeNode> nodes = selection.toList(); boolean moving = (operation & DND.DROP_MOVE) != 0; boolean copying = (operation & DND.DROP_COPY) != 0; if (hovered.isDirectory() && hovered.isWritable() && (moving || copying)) { IFSTreeNode head = nodes.get(0); String hid = head.getPeerNode().getPeerId(); String tid = hovered.getPeerNode().getPeerId(); if (hid.equals(tid)) { for (IFSTreeNode node : nodes) { if (moving && node == hovered || node.getParent() == hovered || node.isAncestorOf(hovered)) { return false; } } return true; } } else if (hovered.isFile() && copying) { hovered = hovered.getParent(); return validateLocalSelectionDrop(hovered, operation, transferType); } return false; }
From source file:org.eclipse.tcf.te.tcf.ui.navigator.dnd.CommonDnD.java
License:Open Source License
/** * Validate dropping when the elements being dragged are local selection. * * @param dropAdapter The common drop adapter. * @param target The target object.// w w w .j a v a 2 s. co m * @param operation The DnD operation. * @param transferType The transfered data type. * * @return true if it is valid for dropping. */ public static boolean validateLocalSelectionDrop(CommonDropAdapter dropAdapter, Object target, int operation, TransferData transferType) { int overrideOperation = -1; boolean valid = false; LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer(); IStructuredSelection selection = (IStructuredSelection) transfer.getSelection(); boolean allow = true; boolean link = false; boolean copy = false; Iterator<?> iterator = selection.iterator(); while (allow && iterator.hasNext()) { Object element = iterator.next(); if (!isDraggableObject(element)) { allow = false; break; } ICategorizable categorizable = getCategorizable(element); if (categorizable == null || !isDraggableObject(element)) { allow = false; break; } ICategory[] parentCategories = getParentCategories(element, selection); if (parentCategories.length == 0) { allow = false; } for (ICategory parentCategory : parentCategories) { if (target instanceof ICategory) { ICategory category = (ICategory) target; if (!link && element instanceof IPeerNode && category.getId().equals(parentCategory.getId())) { overrideOperation = DND.DROP_COPY; copy = true; } else if (!copy && !Managers.getCategoryManager().isLinked(category.getId(), categorizable.getId()) && categorizable.isValid(ICategorizable.OPERATION.ADD, parentCategory, category)) { overrideOperation = DND.DROP_LINK; link = true; } else { allow = false; break; } } else if (target instanceof IRoot) { overrideOperation = DND.DROP_DEFAULT; if (!Managers.getCategoryManager().isLinked(parentCategory.getId(), categorizable.getId())) { allow = false; break; } } } } valid = allow; if (dropAdapter != null) { if (!valid) { dropAdapter.overrideOperation(DND.DROP_NONE); } else if (overrideOperation != -1) { dropAdapter.overrideOperation(overrideOperation); } else { dropAdapter.overrideOperation(operation); } } return valid; }