Search in sources :

Example 81 with Transfer

use of org.eclipse.swt.dnd.Transfer in project BiglyBT by BiglySoftware.

the class TableViewSWT_Common method fillMenu.

/**
 * Fill the Context Menu with items.  Called when menu is about to be shown.
 *
 * By default, a "Edit Columns" menu and a Column specific menu is set up.
 *
 * @param menu Menu to fill
 * @param tcColumn
 */
public void fillMenu(final Menu menu, final TableColumnCore column) {
    String columnName = column == null ? null : column.getName();
    Object[] listeners = listenersMenuFill.toArray();
    for (int i = 0; i < listeners.length; i++) {
        TableViewSWTMenuFillListener l = (TableViewSWTMenuFillListener) listeners[i];
        l.fillMenu(columnName, menu);
    }
    boolean hasLevel1 = false;
    boolean hasLevel2 = false;
    // quick hack so we don't show plugin menus on selections of subitems
    TableRowCore[] selectedRows = tv.getSelectedRows();
    for (TableRowCore row : selectedRows) {
        if (row.getParentRowCore() != null) {
            hasLevel2 = true;
        } else {
            hasLevel1 = true;
        }
    }
    String tableID = tv.getTableID();
    String sMenuID = hasLevel1 ? tableID : TableManager.TABLE_TORRENT_FILES;
    // We'll add download-context specific menu items - if the table is download specific.
    // We need a better way to determine this...
    boolean isDownloadContext;
    com.biglybt.pif.ui.menus.MenuItem[] menu_items = null;
    if (Download.class.isAssignableFrom(tv.getDataSourceType()) && !hasLevel2) {
        menu_items = MenuItemManager.getInstance().getAllAsArray(MenuManager.MENU_DOWNLOAD_CONTEXT);
        isDownloadContext = true;
    } else {
        menu_items = MenuItemManager.getInstance().getAllAsArray((String) null);
        isDownloadContext = false;
    }
    if (columnName == null) {
        MenuItem itemChangeTable = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(itemChangeTable, "MyTorrentsView.menu.editTableColumns");
        Utils.setMenuItemImage(itemChangeTable, "columns");
        itemChangeTable.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                showColumnEditor(column);
            }
        });
    } else {
        MenuItem item = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(item, "MyTorrentsView.menu.thisColumn.toClipboard");
        item.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                String sToClipboard = "";
                if (column == null) {
                    return;
                }
                String columnName = column.getName();
                if (columnName == null) {
                    return;
                }
                TableRowCore[] rows = tv.getSelectedRows();
                for (TableRowCore row : rows) {
                    if (row != rows[0]) {
                        sToClipboard += "\n";
                    }
                    TableCellCore cell = row.getTableCellCore(columnName);
                    if (cell != null) {
                        sToClipboard += cell.getClipboardText();
                    }
                }
                if (sToClipboard.length() == 0) {
                    return;
                }
                new Clipboard(Display.getDefault()).setContents(new Object[] { sToClipboard }, new Transfer[] { TextTransfer.getInstance() });
            }
        });
    }
    // Add Plugin Context menus..
    boolean enable_items = selectedRows.length > 0;
    TableContextMenuItem[] items = TableContextMenuManager.getInstance().getAllAsArray(Utils.getBaseViewID(sMenuID));
    if (items.length > 0 || menu_items.length > 0) {
        new org.eclipse.swt.widgets.MenuItem(menu, SWT.SEPARATOR);
        // Add download context menu items.
        if (menu_items != null) {
            // getSelectedDataSources(false) returns us plugin items.
            Object[] target;
            if (isDownloadContext) {
                Object[] dataSources = tv.getSelectedDataSources(false);
                target = new Download[dataSources.length];
                System.arraycopy(dataSources, 0, target, 0, target.length);
            } else {
                target = selectedRows;
            }
            MenuBuildUtils.addPluginMenuItems(menu_items, menu, true, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(target));
        }
        if (items.length > 0) {
            MenuBuildUtils.addPluginMenuItems(items, menu, true, enable_items, new MenuBuildUtils.PluginMenuController() {

                @Override
                public Listener makeSelectionListener(final com.biglybt.pif.ui.menus.MenuItem plugin_menu_item) {
                    return new TableSelectedRowsListener(tv, false) {

                        @Override
                        public boolean run(TableRowCore[] rows) {
                            if (rows.length != 0) {
                                ((MenuItemImpl) plugin_menu_item).invokeListenersMulti(rows);
                            }
                            return true;
                        }
                    };
                }

                @Override
                public void notifyFillListeners(com.biglybt.pif.ui.menus.MenuItem menu_item) {
                    ((MenuItemImpl) menu_item).invokeMenuWillBeShownListeners(tv.getSelectedRows());
                }

                // @see com.biglybt.ui.swt.MenuBuildUtils.PluginMenuController#buildSubmenu(com.biglybt.pif.ui.menus.MenuItem)
                @Override
                public void buildSubmenu(com.biglybt.pif.ui.menus.MenuItem parent) {
                    com.biglybt.pif.ui.menus.MenuBuilder submenuBuilder = ((MenuItemImpl) parent).getSubmenuBuilder();
                    if (submenuBuilder != null) {
                        try {
                            parent.removeAllChildItems();
                            submenuBuilder.buildSubmenu(parent, tv.getSelectedRows());
                        } catch (Throwable t) {
                            Debug.out(t);
                        }
                    }
                }

                @Override
                public void buildComplete(Menu menu) {
                }
            });
        }
    }
    if (hasLevel1) {
        // Add Plugin Context menus..
        if (column != null) {
            TableContextMenuItem[] columnItems = column.getContextMenuItems(TableColumnCore.MENU_STYLE_COLUMN_DATA);
            if (columnItems.length > 0) {
                new MenuItem(menu, SWT.SEPARATOR);
                MenuBuildUtils.addPluginMenuItems(columnItems, menu, true, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(tv.getSelectedDataSources(true)));
            }
        }
        final MenuItem itemSelectAll = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(itemSelectAll, "Button.selectAll");
        itemSelectAll.addListener(SWT.Selection, (ev) -> {
            tv.selectAll();
        });
        if (tv.getSWTFilter() != null) {
            final MenuItem itemFilter = new MenuItem(menu, SWT.PUSH);
            Messages.setLanguageText(itemFilter, "MyTorrentsView.menu.filter");
            itemFilter.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    tv.openFilterDialog();
                }
            });
        }
        MenuItem itemChangeTable = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(itemChangeTable, "MyTorrentsView.menu.editTableColumns");
        Utils.setMenuItemImage(itemChangeTable, "columns");
        itemChangeTable.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                showColumnEditor(column);
            }
        });
    }
}
Also used : UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) com.biglybt.ui.swt(com.biglybt.ui.swt) Download(com.biglybt.pif.download.Download) Point(org.eclipse.swt.graphics.Point) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Transfer(org.eclipse.swt.dnd.Transfer) Clipboard(org.eclipse.swt.dnd.Clipboard)

Example 82 with Transfer

use of org.eclipse.swt.dnd.Transfer in project translationstudio8 by heartsome.

the class SegmentViewer method parse.

/**
	 * 执行粘贴前对标记的处理 ;
	 */
private void parse() {
    Clipboard clipboard = null;
    try {
        if (getTextWidget().isDisposed()) {
            return;
        }
        clipboard = new Clipboard(getTextWidget().getDisplay());
        XLiffTextTransfer hsTextTransfer = XLiffTextTransfer.getInstance();
        String hsText = (String) clipboard.getContents(hsTextTransfer);
        String osText = (String) clipboard.getContents(TextTransfer.getInstance());
        if (hsText == null || hsText.length() == 0) {
            if (osText == null || osText.length() == 0) {
                return;
            }
            super.doOperation(ITextOperationTarget.PASTE);
            return;
        }
        String clearedTagText = hsText;
        String selText = getTextWidget().getSelectionText();
        if (selText.equals(hsText)) {
            return;
        }
        if (getTextWidget().getSelectionCount() != getTextWidget().getText().length()) {
            // 过滤掉系统剪切板中的标记。
            clearedTagText = filterInnerTag(hsText);
        } else {
            StringBuffer bf = new StringBuffer(hsText);
            Matcher matcher = PATTERN.matcher(hsText);
            List<String> needRemove = new ArrayList<String>();
            while (matcher.find()) {
                String placeHolder = matcher.group();
                InnerTag tag = InnerTagUtil.getInnerTag(innerTagCacheList, placeHolder);
                if (tag == null) {
                    needRemove.add(placeHolder);
                }
            }
            clearedTagText = bf.toString();
            for (String r : needRemove) {
                clearedTagText = clearedTagText.replaceAll(r, "");
            }
        }
        if (clearedTagText == null || clearedTagText.length() == 0) {
            return;
        }
        if (clearedTagText.equals(osText)) {
            super.doOperation(ITextOperationTarget.PASTE);
            return;
        }
        Object[] data = new Object[] { clearedTagText, hsText };
        Transfer[] types = new Transfer[] { TextTransfer.getInstance(), hsTextTransfer };
        try {
            clipboard.setContents(data, types);
        } catch (Exception e) {
            e.printStackTrace();
        }
        super.doOperation(ITextOperationTarget.PASTE);
        data = new Object[] { osText, hsText };
        try {
            clipboard.setContents(data, types);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } finally {
        if (clipboard != null && !clipboard.isDisposed()) {
            clipboard.dispose();
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) BadLocationException(org.eclipse.jface.text.BadLocationException) InnerTag(net.heartsome.cat.common.ui.innertag.InnerTag) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Clipboard(org.eclipse.swt.dnd.Clipboard)

Example 83 with Transfer

use of org.eclipse.swt.dnd.Transfer in project cogtool by cogtool.

the class ProjectUI method setUpDragAndDrop.

// See http://www.eclipse.org/articles/Article-SWT-DND/DND-in-SWT.html
// for more documentation of SWT drag-and-drop support.
protected void setUpDragAndDrop() {
    DragSource treeAsSource = new DragSource(tree, DND.DROP_MOVE | DND.DROP_COPY);
    TaskDnDTransfer taskTransfer = TaskDnDTransfer.getInstance();
    TaskAppDnDTransfer taskAppTransfer = TaskAppDnDTransfer.getInstance();
    Transfer[] types = new Transfer[] { taskTransfer, taskAppTransfer };
    treeAsSource.setTransfer(types);
    // DropSourceEvent fields:
    // dataType:
    //   the Transfer type of the data the target prefers to receive;
    //   useful in dragSetData
    // detail:
    //   the operation the target performed; one of:
    //      DROP_MOVE - move from source to target; remove from source
    //      DROP_COPY - copy the source to target; leave the source
    //      DROP_LINK - create a link of the source at the target
    //   useful in dragFinished in case the source needs to be removed
    // doit:
    //   in dragStart, determines if the operation should proceed
    //   in dragFinished, may be set to indicate if the operation succeeded
    // image:
    //   may be set to the Image displayed during drag
    // x, y: position within the Tree
    DragSourceListener srcListener = new TreeDragSourceEffect(tree) {

        @Override
        public void dragStart(DragSourceEvent evt) {
            // If the Transfer type cannot be determined until the drag
            // starts, the setTransfer() call can be invoked here.
            // Set evt.doit to false here if action is inappropriate.
            // Reset, just in case no drag-and-drop should happen
            currentDnDSource = null;
            // Must be in first column!
            TreeColumn column = findColumn(evt.x);
            TreeItem row = tree.getItem(new Point(evt.x, evt.y));
            if ((column != null) && (column.getData() == null)) {
                if ((row != null) && (row.getData() != null)) {
                    if (((AUndertaking) row.getData()).isSpawned()) {
                        evt.doit = false;
                        return;
                    }
                }
                if (selection.getSelectedTaskCount() == 0) {
                    if (row != null) {
                        selection.setSelectedItem(row);
                        currentDnDSource = tree;
                        currentDnDColumn = 0;
                    }
                } else {
                    currentDnDSource = tree;
                    currentDnDColumn = 0;
                }
            } else {
                // Must be in cell with a valid TaskApplication!
                if ((column != null) && (column.getData() != null)) {
                    if ((row != null) && (row.getData() != null)) {
                        Design design = (Design) column.getData();
                        AUndertaking task = (AUndertaking) row.getData();
                        TaskApplication taskApp = project.getTaskApplication(task, design);
                        if (taskApp != null) {
                            if (!taskApp.getDemonstration().isEditable()) {
                                evt.doit = false;
                                return;
                            }
                            // set some highlighting of the source cell
                            selection.setSelectedCell(row, column);
                            contextSelection.setSelectedDesign(design);
                            contextSelection.addSelectedTask(task);
                            currentDnDRow = row;
                            currentDnDSource = tree;
                            currentDnDColumn = tree.indexOf(column);
                            // do not do superclass work!
                            return;
                        }
                    }
                }
                evt.doit = false;
            }
            super.dragStart(evt);
        }

        @Override
        public void dragSetData(DragSourceEvent evt) {
            // Based on the requested Transfer data type, set evt.data
            //                    if (taskTransfer.isSupportedType(evt.dataType)) {
            //                        evt.data = "This is the requested data";
            //                    }
            super.dragSetData(evt);
        }

        @Override
        public void dragFinished(DragSourceEvent evt) {
            // Operation was performed by the drop target; clean up
            // If needed, evt.detail should be the operation performed.
            super.dragFinished(evt);
            currentDnDSource = null;
            currentDnDColumn = -1;
            currentDnDRow = null;
            currentDndTaskAppDropRow = null;
        }
    };
    treeAsSource.addDragListener(srcListener);
    DropTarget treeAsTarget = new DropTarget(tree, DND.DROP_MOVE | DND.DROP_COPY);
    treeAsTarget.setTransfer(types);
    // DropTargetEvent fields:
    // currentDataType:
    //   the Transfer type of the data the target prefers to receive;
    //   can be set -- see the method comments below
    // dataTypes:
    //   the array of Transfer types the source can "send"
    // detail:
    //   the operation the user is trying to perform; one of:
    //      DROP_MOVE - move from source to target; remove from source
    //      DROP_COPY - copy the source to target; leave the source
    //      DROP_LINK - create a link of the source at the target
    //      DROP_DEFAULT - indicator that target must choose operation
    //      DROP_NONE - indicator that user is trying an unsupported op
    //   may be set to the operation the target feels is correct
    //   (thus, if initially DEFAULT, then the operation that would be
    //   performed; if initially DEFAULT and not changed, it will appear
    //   to the user as a MOVE -- also, set to NONE if target determines
    //   operation is not permitted)
    // feedback:
    //   bitwise OR'ing of feedback effects displayed to the user;
    //   can be set using the following constants:
    //      FEEDBACK_SELECT - item under cursor is selected
    //      FEEDBACK_SCROLL - allows scrolling to make items visible
    //      FEEDBACK_EXPAND - allows tree items to be expanded
    //      FEEDBACK_INSERT_BEFORE - insertion mark before item under cursor
    //      FEEDBACK_INSERT_AFTER - insertion mark after item under cursor
    //      FEEDBACK_NONE - no feedback
    // item:
    //   TreeItem or TableItem under the cursor, if applicable
    // operations:
    //   bitwise OR'ing of the operations that the DragSource can support
    treeAsTarget.addDropListener(new TreeDropTargetEffect(tree) {

        protected static final int DRAG_FEEDBACK = DND.FEEDBACK_EXPAND | DND.FEEDBACK_INSERT_BEFORE | DND.FEEDBACK_SCROLL;

        protected static final int DRAG_APP_FEEDBACK = DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL;

        protected int requestedOp = DND.DROP_MOVE;

        @Override
        public void dragEnter(DropTargetEvent evt) {
            // Set evt.detail to DND.DROP_NONE when the operation is a no-op
            // or if the presented type is unacceptable.  Other choices
            // that make sense: DND.DROP_MOVE, DND.DROP_COPY
            // evt.currentDataType is the type preferred by the target.
            // evt.dataTypes contains types provided by the source.
            super.dragEnter(evt);
            if (currentDnDSource != getControl()) {
                evt.detail = DND.DROP_NONE;
            } else {
                requestedOp = evt.detail;
            }
        }

        @Override
        public void dragLeave(DropTargetEvent evt) {
            if (currentDndTaskAppDropRow != null) {
                currentDndTaskAppDropRow.setBackground(currentDnDColumn, ProjectUIModel.unselectedTaskBackgroundColor);
            }
            super.dragLeave(evt);
        }

        @Override
        public void dragOperationChanged(DropTargetEvent evt) {
            // change evt.currentDataType if desired here.
            if ((evt.detail != DND.DROP_MOVE) && (evt.detail != DND.DROP_COPY)) {
                evt.detail = DND.DROP_NONE;
            }
            requestedOp = evt.detail;
            super.dragOperationChanged(evt);
        }

        @Override
        public void dragOver(DropTargetEvent evt) {
            if (currentDndTaskAppDropRow != null) {
                currentDndTaskAppDropRow.setBackground(currentDnDColumn, ProjectUIModel.unselectedTaskBackgroundColor);
            }
            Point toTreeEvtLoc = tree.toControl(evt.x, evt.y);
            //System.out.println("dragOver; set feedback here?");
            if (currentDnDSource != getControl()) {
                evt.detail = DND.DROP_NONE;
                evt.feedback = DND.FEEDBACK_NONE;
            } else if (currentDnDColumn == 0) {
                // Moving tasks
                evt.feedback = DRAG_FEEDBACK;
                evt.detail = requestedOp;
                TreeItem row = tree.getItem(toTreeEvtLoc);
                if ((row != null) && (row.getData() != null)) {
                    if (((AUndertaking) row.getData()).isSpawned()) {
                        evt.detail = DND.DROP_NONE;
                        evt.feedback = DND.FEEDBACK_NONE;
                    }
                }
            } else {
                // Moving task applications
                evt.feedback = DRAG_APP_FEEDBACK;
                TreeColumn column = findColumn(toTreeEvtLoc.x);
                if (column == null) {
                    evt.detail = DND.DROP_NONE;
                } else {
                    Design design = (Design) column.getData();
                    if (design != contextSelection.getSelectedDesign()) {
                        evt.detail = DND.DROP_NONE;
                    } else {
                        TreeItem row = tree.getItem(toTreeEvtLoc);
                        if ((row == null) || (row.getData() == null)) {
                            evt.detail = DND.DROP_NONE;
                        } else {
                            AUndertaking task = (AUndertaking) row.getData();
                            if (task.isTaskGroup() || task.isSpawned() || contextSelection.isTaskSelected(task)) {
                                evt.detail = DND.DROP_NONE;
                            } else {
                                evt.detail = requestedOp;
                                currentDndTaskAppDropRow = row;
                                currentDndTaskAppDropRow.setBackground(currentDnDColumn, CONTEXT_COLOR);
                            }
                        }
                    }
                }
            }
            super.dragOver(evt);
        }

        @Override
        public void dropAccept(DropTargetEvent evt) {
            // Can change evt.detail if desired here.
            // Provide one last chance to define the type of data that
            // will be returned in the drop event; thus, change
            // evt.currentDataType if desired here
            super.dropAccept(evt);
        }

        @Override
        public void drop(DropTargetEvent evt) {
            // When the drop operation is completed, update the
            // evt.detail field with the operation performed.
            // Do the operation!
            AUndertaking beforeTask = null;
            if (evt.item != null) {
                beforeTask = (AUndertaking) evt.item.getData();
            }
            if (requestedOp == DND.DROP_COPY) {
                if (currentDnDColumn == 0) {
                    ProjectUI.ChangeTaskPositionParms parms = new ProjectUI.ChangeTaskPositionParms(selection, beforeTask, true);
                    if (performAction(ProjectLID.DuplicateTaskFull, parms, true)) {
                        evt.detail = DND.DROP_COPY;
                    }
                } else {
                    AUndertaking fromTask = (AUndertaking) currentDnDRow.getData();
                    AUndertaking toTask = (AUndertaking) currentDndTaskAppDropRow.getData();
                    TreeColumn column = tree.getColumn(currentDnDColumn);
                    Design design = (Design) column.getData();
                    ProjectUI.MoveCopyTaskApplicationParms parms = new ProjectUI.MoveCopyTaskApplicationParms(fromTask, toTask, design);
                    selection.setSelectedCell(currentDndTaskAppDropRow, column);
                    if (performAction(ProjectLID.DuplicateTaskApplication, parms, true)) {
                        uiModel.redisplayAllResults();
                        evt.detail = DND.DROP_COPY;
                    }
                }
            } else if (requestedOp == DND.DROP_MOVE) {
                if (currentDnDColumn == 0) {
                    ProjectUI.ChangeTaskPositionParms parms = new ProjectUI.ChangeTaskPositionParms(selection, beforeTask, false);
                    if (performAction(ProjectLID.ChangeTaskPosition, parms, true)) {
                        evt.detail = DND.DROP_MOVE;
                    }
                } else {
                    AUndertaking fromTask = (AUndertaking) currentDnDRow.getData();
                    AUndertaking toTask = (AUndertaking) currentDndTaskAppDropRow.getData();
                    TreeColumn column = tree.getColumn(currentDnDColumn);
                    Design design = (Design) column.getData();
                    ProjectUI.MoveCopyTaskApplicationParms parms = new ProjectUI.MoveCopyTaskApplicationParms(fromTask, toTask, design);
                    selection.setSelectedCell(currentDndTaskAppDropRow, column);
                    if (performAction(ProjectLID.MoveTaskApplication, parms, true)) {
                        uiModel.redisplayAllResults();
                        evt.detail = DND.DROP_MOVE;
                    }
                }
            }
            super.drop(evt);
        }
    });
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DragSource(org.eclipse.swt.dnd.DragSource) Point(org.eclipse.swt.graphics.Point) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) TreeDropTargetEffect(org.eclipse.swt.dnd.TreeDropTargetEffect) Point(org.eclipse.swt.graphics.Point) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) Design(edu.cmu.cs.hcii.cogtool.model.Design) TreeColumn(org.eclipse.swt.widgets.TreeColumn) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Transfer(org.eclipse.swt.dnd.Transfer) ByteArrayTransfer(org.eclipse.swt.dnd.ByteArrayTransfer) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) DropTarget(org.eclipse.swt.dnd.DropTarget) TreeDragSourceEffect(org.eclipse.swt.dnd.TreeDragSourceEffect)

Example 84 with Transfer

use of org.eclipse.swt.dnd.Transfer in project cubrid-manager by CUBRID.

the class TableSchemaCompareInfoPart method copyTableAlterDDL.

/**
	 * copyTableLeftAlterDDL
	 */
private void copyTableAlterDDL(CubridDatabase leftDB, CubridDatabase rightDB, boolean leftToRight) {
    // FIXME logic code move to core module
    StringBuffer clipboardDataString = new StringBuffer();
    TableItem[] tableItems = tablesSchemaCompareTable.getTable().getSelection();
    String title = "";
    String msg = "";
    for (int i = 0; i < tableItems.length; i++) {
        if (i > 0) {
            clipboardDataString.append(StringUtil.NEWLINE);
            clipboardDataString.append(StringUtil.NEWLINE);
        }
        TableSchemaCompareModel compareModel = (TableSchemaCompareModel) tableItems[i].getData();
        TableSchema leftTableSchema = (TableSchema) compareModel.getLeft();
        TableSchema rightTableSchema = (TableSchema) compareModel.getRight();
        String tableCompare = leftTableSchema.getName();
        if (StringUtil.isEmpty(leftTableSchema.getName())) {
            tableCompare = rightTableSchema.getName();
        }
        String alterDDL = null;
        if (compareModel.getCompareStatus() != TableSchemaCompareModel.SCHEMA_EQUAL && compareModel.getCompareStatus() != TableSchemaCompareModel.RECORDS_DIFF) {
            Map<String, SchemaInfo> sourceSchemas = compareModel.getSourceSchemas();
            Map<String, SchemaInfo> targetSchemas = compareModel.getTargetSchemas();
            SchemaInfo sourceTableSchemaInfo = null;
            SchemaInfo targetTableSchemaInfo = null;
            if (leftToRight) {
                sourceTableSchemaInfo = sourceSchemas.get(tableCompare);
                targetTableSchemaInfo = targetSchemas.get(tableCompare);
            } else {
                targetTableSchemaInfo = sourceSchemas.get(tableCompare);
                sourceTableSchemaInfo = targetSchemas.get(tableCompare);
            }
            alterDDL = tableComp.getTableAlterScript(leftDB, rightDB, tableCompare, sourceTableSchemaInfo, targetTableSchemaInfo);
            if (StringUtil.isNotEmpty(alterDDL)) {
                clipboardDataString.append(alterDDL.trim());
            }
        }
    }
    Clipboard clipboard = CommonUITool.getClipboard();
    if (clipboardDataString.length() != 0) {
        if ("--NotSupportAlterAutoIncrement".equals(clipboardDataString.toString())) {
            title = Messages.compareStatusTip;
            msg = Messages.alterAutoIncrementNotSupport;
        } else {
            TextTransfer textTransfer = TextTransfer.getInstance();
            Transfer[] transfers = new Transfer[] { textTransfer };
            Object[] data = new Object[] { clipboardDataString.toString() };
            clipboard.setContents(data, transfers);
            title = Messages.alterScript;
            msg = Messages.tableSchemaAlterCopyMessage;
        }
    } else {
        clipboard.clearContents();
        title = Messages.emptyAlterScript;
        msg = Messages.schemaIdenticalMessage;
    }
    CommonUITool.openInformationBox(title, msg);
}
Also used : TableSchema(com.cubrid.common.ui.compare.schema.model.TableSchema) TableItem(org.eclipse.swt.widgets.TableItem) TableSchemaCompareModel(com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Clipboard(org.eclipse.swt.dnd.Clipboard) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 85 with Transfer

use of org.eclipse.swt.dnd.Transfer in project cubrid-manager by CUBRID.

the class CubridNavigatorView method addTreeDropTarget.

/**
	 * Add drop target
	 *
	 * @param tree Tree
	 */
private void addTreeDropTarget(final Tree tree) {
    // DropTarget for tree
    Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
    int operations = DND.DROP_MOVE | DND.DROP_COPY;
    DropTarget target = new DropTarget(tree, operations);
    target.setTransfer(types);
    target.addDropListener(new DropTargetAdapter() {

        /**
			 * Drag item enter the tree items
			 */
        public void dragEnter(DropTargetEvent event) {
            TreeItem[] selectedItems = tree.getSelection();
            //do not support multi DROP_COPY
            if (event.detail == DND.DROP_COPY && selectedItems.length > 1) {
                event.detail = DND.DROP_NONE;
                event.feedback = DND.FEEDBACK_NONE;
            }
        }

        /**
			 * When drag operation change, check whether to support this operation
			 */
        public void dragOperationChanged(DropTargetEvent event) {
            dragEnter(event);
        }

        /**
			 * Drag item over the tree items.
			 */
        public void dragOver(DropTargetEvent event) {
            event.feedback = DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL;
            if (event.item == null) {
                event.feedback = DND.FEEDBACK_NONE;
                return;
            }
            //do not support multi DROP_COPY
            TreeItem[] selectedItems = tree.getSelection();
            if (event.detail == DND.DROP_COPY && selectedItems.length > 1) {
                event.feedback = DND.FEEDBACK_NONE;
                return;
            }
            //Target TreeItem
            TreeItem targetTreeItem = (TreeItem) event.item;
            ICubridNode data = (ICubridNode) targetTreeItem.getData();
            if (dataSupportDragOver(data)) {
                if (data instanceof CubridGroupNode) {
                    event.feedback |= DND.FEEDBACK_SELECT;
                    return;
                }
                //Convert drop coordinate from Display to Tree
                Point pt = Display.getCurrent().map(null, tree, event.x, event.y);
                Rectangle bounds = targetTreeItem.getBounds();
                if (pt.y < (bounds.y + bounds.height / 2)) {
                    event.feedback |= DND.FEEDBACK_INSERT_BEFORE;
                } else {
                    //if (pt.y > bounds.y + 2 * bounds.height / 3)
                    event.feedback |= DND.FEEDBACK_INSERT_AFTER;
                }
            } else {
                event.feedback = DND.FEEDBACK_NONE;
            }
        }

        public void drop(DropTargetEvent event) {
            if (event.data == null) {
                event.detail = DND.DROP_NONE;
                return;
            }
            TreeItem[] selectedItems = tree.getSelection();
            if (event.detail == DND.DROP_COPY && selectedItems.length > 1) {
                event.detail = DND.DROP_NONE;
                return;
            }
            final int dropOperation = event.detail;
            ICubridNode dropNode = null;
            boolean insertBefore = false;
            if (event.item == null) {
                List<CubridGroupNode> allGroup = getGroupNodeManager().getAllGroupNodes();
                dropNode = allGroup.get(allGroup.size() - 1);
            } else {
                //Move under a TreeItem node
                TreeItem dropItem = (TreeItem) event.item;
                dropNode = (ICubridNode) dropItem.getData();
                Point pt = Display.getCurrent().map(null, tree, event.x, event.y);
                Rectangle bounds = dropItem.getBounds();
                if (pt.y < bounds.y + bounds.height / 2) {
                    insertBefore = true;
                }
            }
            CubridDnDNodeHandler handler = getCubridDnDNodeHandler();
            boolean isSuccess = false;
            if (insertBefore) {
                for (TreeItem si : selectedItems) {
                    ICubridNode dragNode = (ICubridNode) si.getData();
                    isSuccess = handler.handle(dragNode, dropNode, insertBefore, dropOperation) || isSuccess;
                }
            } else {
                for (int i = selectedItems.length - 1; i >= 0; i--) {
                    TreeItem si = selectedItems[i];
                    ICubridNode dragNode = (ICubridNode) si.getData();
                    isSuccess = handler.handle(dragNode, dropNode, insertBefore, dropOperation) || isSuccess;
                }
            }
            if (isSuccess) {
                Object[] objs = tv.getExpandedElements();
                setTreeInput();
                tv.setExpandedElements(objs);
            }
        }
    });
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) Rectangle(org.eclipse.swt.graphics.Rectangle) CubridDnDNodeHandler(com.cubrid.common.ui.common.navigator.dnd.CubridDnDNodeHandler) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) List(java.util.List) ArrayList(java.util.ArrayList) DropTarget(org.eclipse.swt.dnd.DropTarget)

Aggregations

Transfer (org.eclipse.swt.dnd.Transfer)151 TextTransfer (org.eclipse.swt.dnd.TextTransfer)71 Point (org.eclipse.swt.graphics.Point)63 Clipboard (org.eclipse.swt.dnd.Clipboard)51 Menu (org.eclipse.swt.widgets.Menu)37 IMenuManager (org.eclipse.jface.action.IMenuManager)32 MenuManager (org.eclipse.jface.action.MenuManager)32 Separator (org.eclipse.jface.action.Separator)32 LocalSelectionTransfer (org.eclipse.jface.util.LocalSelectionTransfer)32 EditingDomainViewerDropAdapter (org.eclipse.emf.edit.ui.dnd.EditingDomainViewerDropAdapter)30 LocalTransfer (org.eclipse.emf.edit.ui.dnd.LocalTransfer)30 ViewerDragAdapter (org.eclipse.emf.edit.ui.dnd.ViewerDragAdapter)30 UnwrappingSelectionProvider (org.eclipse.emf.edit.ui.provider.UnwrappingSelectionProvider)30 FileTransfer (org.eclipse.swt.dnd.FileTransfer)30 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)27 DropTarget (org.eclipse.swt.dnd.DropTarget)23 GridData (org.eclipse.swt.layout.GridData)23 GridLayout (org.eclipse.swt.layout.GridLayout)22 Composite (org.eclipse.swt.widgets.Composite)22 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)20