Search in sources :

Example 81 with TreeViewer

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

the class CubridWorkbenchContrItem method checkConnectionStatus.

/**
	 * When selection changed,check whether selected server is connected
	 *
	 * @param selection the ISelection object
	 */
private void checkConnectionStatus(ISelection selection) {
    if (selection == null || selection.isEmpty()) {
        return;
    }
    Object obj = ((IStructuredSelection) selection).getFirstElement();
    if (!(obj instanceof ICubridNode)) {
        return;
    }
    ICubridNode cubridNode = (ICubridNode) obj;
    CubridServer cubridServer = cubridNode.getServer();
    if (cubridServer == null) {
        return;
    }
    ServerInfo serverInfo = cubridServer.getServerInfo();
    boolean needToCheck = !serverInfo.isConnected() && (!(obj instanceof CubridServer) || (cubridServer.getChildren() != null && cubridServer.getChildren().size() > 0));
    if (needToCheck) {
        boolean connectAgagin = false;
        if (CommonUITool.openConfirmBox(Messages.errCannotConnectServerReconnect)) {
            connectAgagin = true;
        }
        closeAllEditorAndViewInServer(cubridServer, false);
        cubridServer.removeAllChild();
        TreeViewer viewer = (TreeViewer) LayoutManager.getInstance().getSelectionProvider();
        viewer.refresh(cubridServer);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(cubridServer, CubridNodeChangedEventType.SERVER_DISCONNECTED));
        if (connectAgagin && connectHost(serverInfo, true)) {
            refreshAfterConnected(cubridServer);
        }
    }
}
Also used : ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) CubridServer(com.cubrid.common.ui.spi.model.CubridServer)

Example 82 with TreeViewer

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

the class CQBConnectionChangingObserver method refreshNavigationTree.

/**
	 * Refresh the navigation tree
	 */
private void refreshNavigationTree(CubridDatabase database) {
    CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridNavigatorView.ID_CQB);
    TreeViewer treeViewer = navigatorView == null ? null : navigatorView.getViewer();
    if (treeViewer == null) {
        return;
    }
    if (database != null) {
        treeViewer.refresh(database, true);
        treeViewer.expandToLevel(database, 1);
    } else {
        CQBDBNodePersistManager.getInstance().reloadDatabases();
        CQBGroupNodePersistManager.getInstance().reloadGroups();
        if (treeViewer != null) {
            treeViewer.refresh(true);
        }
    }
}
Also used : CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) TreeViewer(org.eclipse.jface.viewers.TreeViewer)

Example 83 with TreeViewer

use of org.eclipse.jface.viewers.TreeViewer 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 84 with TreeViewer

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

the class RenameConnectionAction method doRun.

/**
	 * Perform rename Table
	 *
	 * @param cubridDatabase
	 * @param table
	 */
private void doRun(CubridDatabase database) {
    RenameConnectionDialog dlg = new RenameConnectionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), database);
    int ret = dlg.open();
    if (ret == IDialogConstants.OK_ID) {
        /*Fire the database logout*/
        try {
            CubridDatabase orignDatabase = database.clone();
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(orignDatabase, CubridNodeChangedEventType.DATABASE_LOGOUT));
        } catch (CloneNotSupportedException e) {
            LOGGER.error(e.getMessage());
        }
        database.setLabel(dlg.getNewName());
        database.setLogined(false);
        CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridQueryNavigatorView.ID);
        TreeViewer treeViewer = navigatorView == null ? null : navigatorView.getViewer();
        if (treeViewer == null) {
            LOGGER.error("Error: Can't find the navigator view:" + CubridQueryNavigatorView.ID);
            return;
        }
        // Refresh the tree view
        database.removeAllChild();
        treeViewer.refresh(database, true);
        treeViewer.expandToLevel(database, 1);
        setEnabled(false);
        // Save the data
        ServerInfo preServerInfo = (database == null || database.getServer() == null) ? null : database.getServer().getServerInfo();
        QueryOptions.removePref(preServerInfo);
        CQBGroupNodePersistManager.getInstance().saveAllGroupNode();
        CQBDBNodePersistManager.getInstance().saveDatabases();
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        LayoutManager.getInstance().fireSelectionChanged(getSelection());
    }
}
Also used : CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) RenameConnectionDialog(com.cubrid.cubridquery.ui.connection.dialog.RenameConnectionDialog) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 85 with TreeViewer

use of org.eclipse.jface.viewers.TreeViewer 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

TreeViewer (org.eclipse.jface.viewers.TreeViewer)248 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)62 GridData (org.eclipse.swt.layout.GridData)50 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)45 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)43 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)42 Composite (org.eclipse.swt.widgets.Composite)42 Tree (org.eclipse.swt.widgets.Tree)42 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)40 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)39 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)38 CubridNavigatorView (com.cubrid.common.ui.common.navigator.CubridNavigatorView)36 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)36 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)36 GridLayout (org.eclipse.swt.layout.GridLayout)34 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)31 ArrayList (java.util.ArrayList)29 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)27 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)27 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)25