Search in sources :

Example 86 with StructuredSelection

use of org.eclipse.jface.viewers.StructuredSelection in project cubrid-manager by CUBRID.

the class ERSchemaEditor method searchAndLocate.

/**
	 * Set matched tables to be selected, and next(or first) finding table to be
	 * focused
	 * 
	 * @param keyWord
	 * @param isChangedKey
	 * @return
	 */
public boolean searchAndLocate(String keyWord, boolean isChangedKey) {
    SchemaDiagramPart schemaRootPart = getERSchemaRootPart();
    List allParts = schemaRootPart.getChildren();
    // set next focus table(focus circularly )
    if (!isChangedKey && graphicalViewer.getFocusEditPart() instanceof TablePart) {
        TablePart focusedTablePart = (TablePart) graphicalViewer.getFocusEditPart();
        int preFocusIndex = allParts.indexOf(focusedTablePart);
        int start = preFocusIndex + 1;
        for (; start < allParts.size(); start++) {
            Object table = allParts.get(start);
            if (table instanceof TablePart) {
                TablePart nexFocusTable = (TablePart) table;
                if (nexFocusTable.getTable().getShownName().contains(keyWord)) {
                    getViewPort().setViewLocation(nexFocusTable.getFigure().getBounds().x, nexFocusTable.getFigure().getBounds().y);
                    graphicalViewer.setFocus(nexFocusTable);
                    return true;
                }
            }
            if (start == allParts.size()) {
                start = 0;
            }
        }
    }
    // set first focus table and gray tables
    Iterator it = allParts.iterator();
    List matchedList = new ArrayList();
    boolean isFocus = false;
    while (it.hasNext()) {
        Object obj = it.next();
        if (!(obj instanceof TablePart)) {
            continue;
        }
        TablePart tablePart = (TablePart) obj;
        ERTable erTable = tablePart.getTable();
        if (erTable.getShownName().contains(keyWord)) {
            matchedList.add(tablePart);
            if (!isFocus) {
                getViewPort().setViewLocation(tablePart.getFigure().getBounds().x, tablePart.getFigure().getBounds().y);
                graphicalViewer.setFocus(tablePart);
                isFocus = true;
            }
        } else {
            TableFigure figure = (TableFigure) tablePart.getFigure();
            figure.setDisabled(true);
        }
    }
    StructuredSelection matchedTables = new StructuredSelection(matchedList);
    graphicalViewer.setSelection(matchedTables);
    return true;
}
Also used : TableFigure(com.cubrid.common.ui.er.figures.TableFigure) SchemaDiagramPart(com.cubrid.common.ui.er.part.SchemaDiagramPart) TablePart(com.cubrid.common.ui.er.part.TablePart) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ERTable(com.cubrid.common.ui.er.model.ERTable) ArrayList(java.util.ArrayList) List(java.util.List) EventObject(java.util.EventObject) Point(org.eclipse.draw2d.geometry.Point)

Example 87 with StructuredSelection

use of org.eclipse.jface.viewers.StructuredSelection in project cubrid-manager by CUBRID.

the class CommonUITool method addNodeToTree.

/**
	 *
	 * Add new node to parent node in model and add this node to tree
	 *
	 * @param viewer The TreeViewer
	 * @param parent The parent node
	 * @param node The added node
	 */
public static void addNodeToTree(TreeViewer viewer, ICubridNode parent, ICubridNode node) {
    if (parent == null || node == null) {
        return;
    }
    parent.addChild(node);
    viewer.insert(parent, node, parent.position(node));
    viewer.setSelection(new StructuredSelection(node), true);
}
Also used : StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Example 88 with StructuredSelection

use of org.eclipse.jface.viewers.StructuredSelection in project cubrid-manager by CUBRID.

the class DeleteDatabaseAction method run.

public void run() {
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj[0])) {
        setEnabled(false);
        return;
    }
    ISelectionProvider provider = this.getSelectionProvider();
    if (!(provider instanceof TreeViewer)) {
        return;
    }
    ISchemaNode node = (ISchemaNode) obj[0];
    CubridDatabase database = node.getDatabase();
    if (database == null) {
        CommonUITool.openErrorBox(getShell(), Messages.msgSelectDB);
        return;
    }
    CommonQueryTask<DbSpaceInfoList> task = new CommonQueryTask<DbSpaceInfoList>(database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), new DbSpaceInfoList());
    task.setDbName(database.getName());
    TaskExecutor taskExcutor = new CommonTaskExec(Messages.getDbSpaceInfoTaskName);
    taskExcutor.addTask(task);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return;
    }
    DeleteDatabaseDialog dlg = new DeleteDatabaseDialog(getShell());
    dlg.setDbSpaceInfo(task.getResultModel());
    dlg.setDatabase(database);
    ICubridNode parent = database.getParent();
    if (dlg.open() == DeleteDatabaseDialog.DELETE_ID) {
        boolean isContinue = DatabaseUtils.processDatabaseDeleted(database);
        if (isContinue) {
            TreeViewer viewer = (TreeViewer) provider;
            parent.removeChild(database);
            viewer.remove(parent, obj);
            viewer.setSelection(new StructuredSelection(parent));
        }
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DeleteDatabaseDialog(com.cubrid.cubridmanager.ui.cubrid.database.dialog.DeleteDatabaseDialog) TreeViewer(org.eclipse.jface.viewers.TreeViewer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) DbSpaceInfoList(com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 89 with StructuredSelection

use of org.eclipse.jface.viewers.StructuredSelection in project cubrid-manager by CUBRID.

the class PasteQueryConnAction method run.

/**
	 * Paste the query connection
	 */
public void run() {
    Object[] objs = this.getSelectedObj();
    if (!isSupported(objs[0])) {
        setEnabled(false);
        return;
    }
    objs = null;
    ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection strSelection = (IStructuredSelection) selection;
        objs = strSelection.toArray();
    }
    if (objs == null || objs.length == 0) {
        return;
    }
    if (!(objs[0] instanceof CubridDatabase)) {
        return;
    }
    CubridDatabase pastedDb = (CubridDatabase) objs[0];
    QueryConnDialog dialog = new QueryConnDialog(getShell(), pastedDb, true);
    int returnCode = dialog.open();
    if (returnCode == QueryConnDialog.CONNECT_ID || returnCode == QueryConnDialog.SAVE_ID) {
        CubridDatabase database = dialog.getDatabase();
        CQBDBNodePersistManager.getInstance().addDatabase(database, false);
        CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridQueryNavigatorView.ID);
        TreeViewer treeViewer = navigatorView == null ? null : navigatorView.getViewer();
        if (treeViewer == null) {
            return;
        }
        Tree tree = treeViewer.getTree();
        TreeItem item;
        CubridGroupNode parent = getParentGroupNode();
        if (navigatorView.isShowGroup()) {
            item = new TreeItem(navigatorView.getTreeItemByData(parent), SWT.NONE);
        } else {
            item = new TreeItem(tree, SWT.NONE);
        }
        parent.addChild(database);
        CQBGroupNodePersistManager.getInstance().saveAllGroupNode();
        item.setText(database.getLabel());
        item.setData(database);
        treeViewer.refresh(database, true);
        treeViewer.expandToLevel(database, 1);
        treeViewer.setSelection(new StructuredSelection(database), true);
        if (returnCode == QueryConnDialog.CONNECT_ID) {
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGIN));
        }
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) ISelection(org.eclipse.jface.viewers.ISelection) Tree(org.eclipse.swt.widgets.Tree) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) QueryConnDialog(com.cubrid.cubridquery.ui.connection.dialog.QueryConnDialog)

Example 90 with StructuredSelection

use of org.eclipse.jface.viewers.StructuredSelection in project cubrid-manager by CUBRID.

the class CreateConnectionByUrlWizard method performFinish.

/**
	 * Perform finish
	 */
public boolean performFinish() {
    List<CubridDatabase> parsedDatabaseList = connectionPriviewPage.getParsedConnection();
    /*Add the database list to the tree*/
    CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridQueryNavigatorView.ID);
    TreeViewer treeViewer = navigatorView == null ? null : navigatorView.getViewer();
    if (treeViewer == null) {
        return false;
    }
    for (CubridDatabase database : parsedDatabaseList) {
        CQBDBNodePersistManager.getInstance().addDatabase(database, false);
        Tree tree = treeViewer.getTree();
        TreeItem item;
        CubridGroupNode parent = CQBGroupNodePersistManager.getInstance().getDefaultGroup();
        if (navigatorView.isShowGroup()) {
            item = new TreeItem(navigatorView.getTreeItemByData(parent), SWT.NONE);
        } else {
            item = new TreeItem(tree, SWT.NONE);
        }
        parent.addChild(database);
        item.setText(database.getLabel());
        item.setData(database);
        treeViewer.refresh(database, true);
        treeViewer.expandToLevel(database, 1);
        treeViewer.setSelection(new StructuredSelection(database), true);
    }
    CQBGroupNodePersistManager.getInstance().saveAllGroupNode();
    return true;
}
Also used : CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Tree(org.eclipse.swt.widgets.Tree) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Aggregations

StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)256 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)133 ArrayList (java.util.ArrayList)59 ISelection (org.eclipse.jface.viewers.ISelection)43 List (java.util.List)35 GridData (org.eclipse.swt.layout.GridData)28 TreeViewer (org.eclipse.jface.viewers.TreeViewer)25 Composite (org.eclipse.swt.widgets.Composite)24 SelectionEvent (org.eclipse.swt.events.SelectionEvent)21 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)20 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)20 IFile (org.eclipse.core.resources.IFile)19 Label (org.eclipse.swt.widgets.Label)19 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)18 GridLayout (org.eclipse.swt.layout.GridLayout)18 Shell (org.eclipse.swt.widgets.Shell)17 IViewPart (org.eclipse.ui.IViewPart)15 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)15 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)14 Button (org.eclipse.swt.widgets.Button)14