Search in sources :

Example 56 with TreeItem

use of org.eclipse.swt.widgets.TreeItem in project cubrid-manager by CUBRID.

the class CubridNavigatorView method setFocus.

/**
	 * Call this method when focus
	 */
public void setFocus() {
    if (tv == null || tv.getControl() == null || tv.getControl().isDisposed()) {
        return;
    }
    tv.getControl().setFocus();
    // select the first element by default
    int count = tv.getTree().getSelectionCount();
    TreeItem[] items = tv.getTree().getItems();
    if (count == 0 && items != null && items.length > 0) {
        tv.getTree().select(items[0]);
    }
    ActionManager.getInstance().changeSelectionProvider(tv);
    LayoutManager.getInstance().changeSelectionProvider(tv);
    CubridNodeManager.getInstance().addCubridNodeChangeListener(LayoutManager.getInstance());
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) Point(org.eclipse.swt.graphics.Point)

Example 57 with TreeItem

use of org.eclipse.swt.widgets.TreeItem in project cubrid-manager by CUBRID.

the class CubridNavigatorView method addListener.

/**
	 *
	 * Add listener
	 *
	 */
protected void addListener() {
    tv.getTree().addMouseListener(new MouseAdapter() {

        public void mouseDown(MouseEvent event) {
            if (toolTip.isVisible()) {
                toolTip.setVisible(false);
            }
        }

        public void mouseUp(MouseEvent event) {
            if (event.button == 1 && LayoutManager.getInstance().isUseClickOnce()) {
                ISelection selection = tv.getSelection();
                if (selection == null || selection.isEmpty()) {
                    return;
                }
                Object obj = ((IStructuredSelection) selection).getFirstElement();
                if (!(obj instanceof ICubridNode)) {
                    return;
                }
                ICubridNode cubridNode = (ICubridNode) obj;
                LayoutManager.getInstance().getWorkbenchContrItem().openEditorOrView(cubridNode);
            }
        }
    });
    tv.getTree().addMouseTrackListener(new MouseTrackAdapter() {

        public void mouseHover(MouseEvent event) {
            if (toolTip.isVisible()) {
                toolTip.setVisible(false);
            }
            int x = event.x;
            int y = event.y;
            TreeItem item = tv.getTree().getItem(new Point(x, y));
            if (item == null) {
                return;
            }
            showToolTip(item);
        }
    });
    tv.getTree().addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent event) {
            widgetSelected(event);
        }

        public void widgetSelected(SelectionEvent event) {
            if (toolTip.isVisible()) {
                toolTip.setVisible(false);
            }
            TreeItem[] items = tv.getTree().getSelection();
            if (items == null || items.length == 0) {
                return;
            }
            showToolTip(items[0]);
            if (items.length == 1) {
                showSchemaInfo(items[0]);
            } else {
                showSchemaInfo(null);
            }
        }
    });
    addDragDropSupport(tv.getTree());
    tv.getTree().addKeyListener(new KeyListener() {

        public void keyReleased(KeyEvent e) {
        }

        public void keyPressed(KeyEvent e) {
            // prevent to make events by key press for a long time
            if (e.character == ' ') {
                TreeItem[] items = tv.getTree().getSelection();
                if (items == null || items.length == 0) {
                    return;
                }
                if (items.length == 1) {
                    showSchemaInfo(items[0]);
                } else {
                    showSchemaInfo(null);
                }
            }
            lastKeyInputTimestamp = System.currentTimeMillis();
            // by showing object information tab on the query editor.
            if (e.keyCode == SWT.F2) {
                TreeItem[] items = tv.getTree().getSelection();
                if (items == null || items.length == 0) {
                    return;
                }
                for (TreeItem item : items) {
                    Object obj = item.getData();
                    if (obj instanceof ICubridNode) {
                        ICubridNode node = (ICubridNode) obj;
                        if (NodeType.USER_TABLE.equals(node.getType()) || NodeType.SYSTEM_TABLE.equals(node.getType()) || NodeType.USER_VIEW.equals(node.getType()) || NodeType.SYSTEM_VIEW.equals(node.getType())) {
                            DefaultSchemaNode table = (DefaultSchemaNode) obj;
                            OpenTargetAction action = new OpenTargetAction();
                            action.showObjectInfo(table);
                        } else if (NodeType.TABLE_FOLDER.equals(node.getType())) {
                            CubridNavigatorView view = CubridNavigatorView.getNavigatorView(ID_CQB);
                            if (view == null) {
                                view = CubridNavigatorView.getNavigatorView(ID_CM);
                            }
                            if (view == null) {
                                return;
                            }
                            TreeViewer treeViewer = view.getViewer();
                            //if not expand ,expand the node and wait until all children be added
                            if (!treeViewer.getExpandedState(node)) {
                                treeViewer.expandToLevel(node, 1);
                                while (node.getChildren().size() == 0) {
                                    try {
                                        Thread.sleep(500);
                                    } catch (Exception ignored) {
                                    }
                                }
                            }
                            CubridDatabase database = (CubridDatabase) node.getParent();
                            OpenTargetAction action = new OpenTargetAction();
                            action.showTableDashboard(database);
                        }
                    }
                }
            }
        }
    });
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) MouseAdapter(org.eclipse.swt.events.MouseAdapter) MouseTrackAdapter(org.eclipse.swt.events.MouseTrackAdapter) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) Point(org.eclipse.swt.graphics.Point) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) OpenTargetAction(com.cubrid.common.ui.common.action.OpenTargetAction) KeyEvent(org.eclipse.swt.events.KeyEvent) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) KeyListener(org.eclipse.swt.events.KeyListener) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 58 with TreeItem

use of org.eclipse.swt.widgets.TreeItem in project cubrid-manager by CUBRID.

the class FavoriteQueryNavigatorView method getCurrentDatabase.

/**
	 * Return current selected database from the navigation tree.
	 * @return CubridDatabase
	 */
private CubridDatabase getCurrentDatabase() {
    CubridDatabase cubridDatabase = null;
    CubridNavigatorView nav = CubridNavigatorView.findNavigationView();
    if (nav != null) {
        TreeItem[] items = nav.getSelectedItems();
        if (items.length > 0 && items[0] != null && items[0].getData() instanceof ISchemaNode) {
            ISchemaNode node = (ISchemaNode) items[0].getData();
            CubridDatabase tempDatabase = node.getDatabase();
            if (tempDatabase != null && tempDatabase.isLogined()) {
                cubridDatabase = tempDatabase;
            }
        }
    }
    return cubridDatabase;
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 59 with TreeItem

use of org.eclipse.swt.widgets.TreeItem in project cubrid-manager by CUBRID.

the class OIDNavigatorDialog method find.

/**
	 * 
	 * Execute to find result
	 * 
	 * @return <code>true</code> if it is found;<code>false</code>otherwise
	 */
public boolean find() {
    boolean isOk = true;
    resultTree.removeAll();
    TreeItem root = new TreeItem(resultTree, SWT.NONE);
    isOk = searchOID(oidValueText.getText(), root);
    if (!root.isDisposed()) {
        root.setExpanded(true);
    }
    if (!resultTree.isDisposed()) {
        resultTree.layout(true);
    }
    return isOk;
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem)

Example 60 with TreeItem

use of org.eclipse.swt.widgets.TreeItem in project cubrid-manager by CUBRID.

the class OIDNavigatorDialog method createDialogArea.

/**
	 * Create dialog area content
	 * 
	 * @param parent the parent composite
	 * @return the control
	 */
protected Control createDialogArea(Composite parent) {
    Composite parentComp = (Composite) super.createDialogArea(parent);
    Composite composite = new Composite(parentComp, SWT.NONE);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout();
    layout.numColumns = 5;
    layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
    layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
    layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    composite.setLayout(layout);
    Label oidValueLabel = new Label(composite, SWT.LEFT);
    oidValueLabel.setText(Messages.lblOIDValue);
    oidValueLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    oidValueText = new Text(composite, SWT.LEFT | SWT.BORDER);
    oidValueText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 3, 1, -1, -1));
    if (oidStr != null) {
        oidValueText.setText(oidStr);
    }
    oidValueText.addModifyListener(this);
    findButton = new Button(composite, SWT.CENTER);
    findButton.setText(Messages.btnFind);
    findButton.setLayoutData(CommonUITool.createGridData(1, 1, 60, -1));
    if (oidStr == null || oidStr.trim().length() <= 0) {
        findButton.setEnabled(false);
    }
    findButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            find();
        }
    });
    Composite findResultComp = new Composite(composite, SWT.BORDER);
    findResultComp.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 5, 1, -1, 200));
    findResultComp.setLayout(new GridLayout());
    resultTree = new Tree(findResultComp, SWT.NONE | SWT.VIRTUAL);
    GridData data = new GridData(GridData.FILL_BOTH);
    resultTree.setLayoutData(data);
    resultTree.addTreeListener(new TreeListener() {

        public void treeCollapsed(TreeEvent event) {
        //empty
        }

        public void treeExpanded(TreeEvent event) {
            TreeItem item = (TreeItem) event.item;
            if (item.getData(OID_ITEM_FLAG) == null || (item.getData(EXPANDED_ITEM_FLAG) != null)) {
                return;
            }
            if (item.getItemCount() > 0) {
                Object obj = item.getItem(0).getData(DUMY_ITEM_FLAG);
                if (obj instanceof String && OIDNavigatorDialog.DUMY_ITEM_FLAG.equals((String) obj)) {
                    item.removeAll();
                }
            }
            searchOID((String) (item.getData(OID_ITEM_FLAG)), item);
            item.setData(EXPANDED_ITEM_FLAG, "true");
        }
    });
    setTitle(Messages.titleOIDNavigatorDialog);
    setMessage(Messages.msgOIDNavigatorDialog);
    return parentComp;
}
Also used : TreeListener(org.eclipse.swt.events.TreeListener) Composite(org.eclipse.swt.widgets.Composite) TreeItem(org.eclipse.swt.widgets.TreeItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) TreeEvent(org.eclipse.swt.events.TreeEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree)

Aggregations

TreeItem (org.eclipse.swt.widgets.TreeItem)226 Tree (org.eclipse.swt.widgets.Tree)71 Point (org.eclipse.swt.graphics.Point)56 TreeColumn (org.eclipse.swt.widgets.TreeColumn)30 GridData (org.eclipse.swt.layout.GridData)29 Test (org.junit.Test)28 SelectionEvent (org.eclipse.swt.events.SelectionEvent)27 ArrayList (java.util.ArrayList)24 GridLayout (org.eclipse.swt.layout.GridLayout)23 Composite (org.eclipse.swt.widgets.Composite)22 TableItem (org.eclipse.swt.widgets.TableItem)21 Button (org.eclipse.swt.widgets.Button)20 Table (org.eclipse.swt.widgets.Table)20 TreeViewer (org.eclipse.jface.viewers.TreeViewer)19 FillLayout (org.eclipse.swt.layout.FillLayout)19 Label (org.eclipse.swt.widgets.Label)18 Group (org.eclipse.swt.widgets.Group)17 Text (org.eclipse.swt.widgets.Text)17 SelectionListener (org.eclipse.swt.events.SelectionListener)16 Rectangle (org.eclipse.swt.graphics.Rectangle)16