private void attachDropListener() { dropTarget = new DropTarget(targetTable, DND.DROP_MOVE); dropTarget.setTransfer(new Transfer[] { TextTransfer.getInstance() }); dropTarget.addDropListener(new DropTargetAdapter() { public void drop(DropTargetEvent event) { for (String fieldName : getformatedData((String) event.data)) { if(isPropertyAlreadyExists(fieldName)){ return; }else{ ExcelConfigurationDataStructure excelConfigurationDataStructure = new ExcelConfigurationDataStructure(); excelConfigurationDataStructure.setFieldName(fieldName); listOfExcelConfiguration.add(excelConfigurationDataStructure); targetTableViewer.refresh(); draggedFields.add(fieldName); enableDeleteButton(); } } combo.setItems(convertToArray(draggedFields)); combo.select(0); top_composite.layout(); top_composite.getParent().layout(); highlightDropFields(); } }); }
@Override public void createPartControl(Composite parent) { parent.setLayout(new FillLayout()); this.container = parent; CellEditorGlobalActionHanlder.getInstance().setIActionBars(getViewSite().getActionBars()); DropTarget target = new DropTarget(parent, DND.DROP_MOVE | DND.DROP_COPY); Transfer[] tfs = new Transfer[] { FileTransfer.getInstance() }; target.setTransfer(tfs); target.addDropListener(new DropTargetAdapter() { @Override public void drop(DropTargetEvent event) { Object o = event.data; if (o instanceof String[]) { String[] s = (String[]) o; if (s.length == 0 && s[0] == null || s[0].length() == 0) { return; } File f = new File(s[0]); if (f.exists() && f.isFile()) { open(f); } } } }); }
public static void setupFileDrop(Control ctrl) { DropTarget dt = new DropTarget(ctrl, DND.DROP_DEFAULT | DND.DROP_MOVE); dt.setTransfer(new Transfer[] {FileTransfer.getInstance()}); dt.addDropListener(new DropTargetAdapter() { public void drop(DropTargetEvent event) { FileTransfer ft = FileTransfer.getInstance(); if (ft.isSupportedType(event.currentDataType)) { String[] files = (String[]) event.data; for (String file : files) { if (file.toLowerCase().endsWith(".eml")) ImportExportUtilities.importFromEmailFile(file); else if (file.toLowerCase().endsWith(".mbx")) ImportExportUtilities.importFromMbox(file); } } } }); }
public static void addDropSupport(TreeViewer tree, final IModelDropHandler handler) { final Transfer transfer = ModelTransfer.getInstance(); DropTarget dropTarget = new DropTarget(tree.getTree(), DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_DEFAULT); dropTarget.setTransfer(new Transfer[] { transfer }); dropTarget.addDropListener(new DropTargetAdapter() { @Override public void drop(DropTargetEvent event) { if (!transfer.isSupportedType(event.currentDataType)) return; List<BaseDescriptor> list = ModelTransfer .getBaseDescriptors(event.data); handler.handleDrop(list); } }); }
private void addDropSupport() { DropTarget dropTarget = new DropTarget(targetList, DND.DROP_MOVE); dropTarget.setTransfer(new Transfer[] { TextTransfer.getInstance() }); dropTarget.addDropListener(new DropTargetAdapter() { public void drop(DropTargetEvent event) { for (String formattedPackageName : ExpressionEditorUtil.INSTANCE.getformatedData((String) event.data)) { if (isFieldAvailable(formattedPackageName)){ targetList.add(formattedPackageName); removeAddedPackageNameFromSourceList(formattedPackageName); categoriesDialogSourceComposite.enableOrDisableAddLabelsOnComboSelection(); } } } }); }
private void addDropSupport() { DropTarget dropTarget = new DropTarget(expressionEditor, DND.DROP_MOVE); dropTarget.setTransfer(new Transfer[] { TextTransfer.getInstance() }); dropTarget.addDropListener(new DropTargetAdapter() { public void drop(DropTargetEvent event) { for (String fieldName :ExpressionEditorUtil.INSTANCE.getformatedData((String) event.data)){ expressionEditor.insert(SWT.SPACE+fieldName+SWT.SPACE); } } }); }
public void createPartControl(Composite parent) { //viewer this.parent = parent; documentListener = new ViewDocumentListener(); tabfolder = new TabFolder(parent,0); tabfolder.addSelectionListener(new TabSelectionListener()); viewer = new LogFileViewer(tabfolder,SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); // DnD DropTarget target = new DropTarget(parent, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK); target.setTransfer(new Transfer[] {FileTransfer.getInstance(), TextTransfer.getInstance()}); target.addDropListener (new DropTargetAdapter() { public void dragEnter(DropTargetEvent e) { if (e.detail == DND.DROP_NONE) e.detail = DND.DROP_COPY; } public void drop(DropTargetEvent event) { if (event.data == null || ((String[])event.data).length < 1) { event.detail = DND.DROP_NONE; return; } //File file = new File(((String[])event.data)[0]); if (!checkAndOpenFile(LogFileType.LOGFILE_SYSTEM_FILE,((String[])event.data)[0], false)) event.detail = DND.DROP_NONE; } }); // fill the menues makeActions(); hookContextMenu(); contributeToActionBars(); openAllLastOpenFiles(); }
private void initDragAndDrop() { for (int i= 0; i < fAllViewers.length; i++) { addDragAdapters(fAllViewers[i]); addDropAdapters(fAllViewers[i]); } addDragAdapters(fMethodsViewer); fMethodsViewer.addDropSupport(DND.DROP_NONE, new Transfer[0], new DropTargetAdapter()); //DND on empty hierarchy DropTarget dropTarget = new DropTarget(fPagebook, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK | DND.DROP_DEFAULT); dropTarget.setTransfer(new Transfer[] { LocalSelectionTransfer.getInstance() }); dropTarget.addDropListener(new TypeHierarchyTransferDropAdapter(this, fAllViewers[0])); }
private void addDropListener(Composite parent) { LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer(); DropTargetAdapter dragAdapter = new DropTargetAdapter() { @Override public void drop(DropTargetEvent event) { Control droppedObj = (Control) ((StructuredSelection) transfer.getSelection()).getFirstElement(); // Get the existing parent of the dragged control Composite oldParent = droppedObj.getParent(); if (oldParent == parent) { return; } if (droppedObj instanceof Label) { System.out.println("Dropped"); } // handle the drop if (droppedObj instanceof Label) { Label droppedLabel = (Label) droppedObj; droppedLabel.setParent(parent); // Change parent } if (droppedObj instanceof Button) { Button droppedButton = (Button) droppedObj; droppedButton.setParent(parent); // Change parent } // request a layout pass oldParent.requestLayout(); // If you change that to layout the layout will be correct parent.layout(); } }; DropTarget dropTarget = new DropTarget(parent, DND.DROP_MOVE | DND.DROP_COPY); dropTarget.setTransfer(new Transfer[] { transfer }); dropTarget.addDropListener(dragAdapter); }
public static void addDropSupport(TableViewer table, IModelDropHandler handler) { final Transfer transfer = ModelTransfer.getInstance(); DropTarget dropTarget = new DropTarget(table.getTable(), DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_DEFAULT); dropTarget.setTransfer(new Transfer[] { transfer }); dropTarget.addDropListener(new DropTargetAdapter() { @Override public void drop(DropTargetEvent event) { if (!transfer.isSupportedType(event.currentDataType)) return; List<BaseDescriptor> list = ModelTransfer .getBaseDescriptors(event.data); handler.handleDrop(list); } }); }
private void createTargetTable(Composite container) { targetTableViewer = new TableViewer(container, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); targetTable = targetTableViewer.getTable(); GridData gd_table_1 = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2); gd_table_1.heightHint = 401; if(OSValidator.isMac()){ gd_table_1.widthHint = 363; }else{ gd_table_1.widthHint = 352; } targetTable.setLayoutData(gd_table_1); attachTargetTableListeners(); targetTableViewer.setContentProvider(new SecondaryColumnKeysContentProvider()); targetTableViewer.setLabelProvider(new SecondaryColumnKeysLabelProvider()); targetTableViewer.setInput(propertyList); TableColumn targetTableColumnFieldName = new TableColumn(targetTable, SWT.LEFT); targetTableColumnFieldName.setText(COLUMNNAME); //$NON-NLS-1$ TableColumn targetTableColumnSortOrder = new TableColumn(targetTable, SWT.LEFT_TO_RIGHT); targetTableColumnSortOrder.setText(SORTORDER); //$NON-NLS-1$ for (int i = 0, n = targetTable.getColumnCount(); i < n; i++) { targetTable.getColumn(i).pack(); } targetTableColumnFieldName.setWidth(175); if(OSValidator.isMac()){ targetTableColumnSortOrder.setWidth(128); }else{ targetTableColumnSortOrder.setWidth(116); } targetTable.setHeaderVisible(true); targetTable.setLinesVisible(true); // enables the tab functionality TableViewerEditor.create(targetTableViewer, new ColumnViewerEditorActivationStrategy(targetTableViewer), ColumnViewerEditor.KEYBOARD_ACTIVATION | ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL); final CellEditor propertyNameeditor = new TextCellEditor(targetTable); ComboBoxViewerCellEditor propertyValueeditor = new ComboBoxViewerCellEditor(targetTable, SWT.READ_ONLY); propertyValueeditor.setContentProvider(new ArrayContentProvider()); propertyValueeditor.setLabelProvider(new LabelProvider()); propertyValueeditor.setInput(new String[] { Constants.ASCENDING_SORT_ORDER, Constants.DESCENDING_SORT_ORDER, Constants.NONE_SORT_ORDER }); CellEditor[] editors = new CellEditor[] { propertyNameeditor, propertyValueeditor }; propertyNameeditor.setValidator(createNameEditorValidator(Messages.EmptyColumnNotification)); propertyValueeditor.setValidator(createValueEditorValidator(Messages.EmptySortOrderNotification)); targetTableViewer.setColumnProperties(PROPS); targetTableViewer.setCellModifier(new SecondaryColumnKeysWidgetCellModifier(targetTableViewer)); targetTableViewer.setCellEditors(editors); loadProperties(targetTableViewer); if (propertyList.size() != 0) { deleteButton.setEnabled(true); } if (propertyList.size() >= 2) { upButton.setEnabled(true); downButton.setEnabled(true); } dropTarget = new DropTarget(targetTable, DND.DROP_MOVE); dropTarget.setTransfer(new Transfer[] { TextTransfer.getInstance() }); dropTarget.addDropListener(new DropTargetAdapter() { public void drop(DropTargetEvent event) { for (String fieldName : getformatedData((String) event.data)) addNewProperty(targetTableViewer, fieldName); enableControlButtons(); } }); }
protected DropTargetAdapter getDropTargetListener() { return new ExampleDropTargetListener(); }