Search in sources :

Example 1 with CombinedQueryEditorComposite

use of com.cubrid.common.ui.query.control.CombinedQueryEditorComposite in project cubrid-manager by CUBRID.

the class CheckQueryEditorTask method doSave.

public void doSave() {
    ApplicationPersistUtil.getInstance().clearAllEditorStatus();
    Display.getDefault().syncExec(new Runnable() {

        public void run() {
            Date createTime = new Date();
            List<QueryEditorPart> editorPartList = QueryEditorUtil.getAllQueryEditorPart();
            for (QueryEditorPart editor : editorPartList) {
                ArrayList<RestorableQueryEditorInfo> sqlTabItemList = new ArrayList<RestorableQueryEditorInfo>();
                for (CombinedQueryEditorComposite combinedQueryEditorComposite : editor.getAllCombinedQueryEditorComposite()) {
                    StyledText text = combinedQueryEditorComposite.getSqlEditorComp().getText();
                    if (text == null) {
                        LOGGER.warn("The editor.getSqlTextEditor() is a null.");
                        continue;
                    }
                    if (StringUtil.isEmpty(text.getText())) {
                        LOGGER.warn("The text.getText() is a null.");
                        continue;
                    }
                    CubridDatabase cubridDatabase = editor.getSelectedDatabase();
                    RestorableQueryEditorInfo editorStatus = new RestorableQueryEditorInfo();
                    if (cubridDatabase != null) {
                        DatabaseInfo dbInfo = cubridDatabase.getDatabaseInfo();
                        if (dbInfo != null) {
                            editorStatus.setDatabaseName(dbInfo.getDbName());
                        }
                        CubridServer cubridServer = cubridDatabase.getServer();
                        if (cubridServer != null) {
                            editorStatus.setServerName(cubridServer.getId());
                        }
                    }
                    editorStatus.setQueryContents(text.getText());
                    editorStatus.setCreatedTime(createTime);
                    sqlTabItemList.add(editorStatus);
                }
                ApplicationPersistUtil.getInstance().addEditorStatus(sqlTabItemList);
            }
        }
    });
    ApplicationPersistUtil.getInstance().save();
}
Also used : QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) StyledText(org.eclipse.swt.custom.StyledText) CombinedQueryEditorComposite(com.cubrid.common.ui.query.control.CombinedQueryEditorComposite) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) RestorableQueryEditorInfo(com.cubrid.common.ui.spi.model.RestorableQueryEditorInfo) Date(java.util.Date)

Example 2 with CombinedQueryEditorComposite

use of com.cubrid.common.ui.query.control.CombinedQueryEditorComposite in project cubrid-manager by CUBRID.

the class QueryEditorPart method getAllCombinedQueryEditorComposite.

public List<CombinedQueryEditorComposite> getAllCombinedQueryEditorComposite() {
    List<CombinedQueryEditorComposite> combinedQueryEditorCompositeList = new ArrayList<CombinedQueryEditorComposite>();
    CTabItem[] items = combinedQueryEditortabFolder.getItems();
    for (CTabItem item : items) {
        if (item instanceof SubQueryEditorTabItem) {
            CombinedQueryEditorComposite combinedQueryEditorComposite = ((SubQueryEditorTabItem) item).getControl();
            combinedQueryEditorCompositeList.add(combinedQueryEditorComposite);
        }
    }
    return combinedQueryEditorCompositeList;
}
Also used : CombinedQueryEditorComposite(com.cubrid.common.ui.query.control.CombinedQueryEditorComposite) ArrayList(java.util.ArrayList) CTabItem(org.eclipse.swt.custom.CTabItem)

Example 3 with CombinedQueryEditorComposite

use of com.cubrid.common.ui.query.control.CombinedQueryEditorComposite in project cubrid-manager by CUBRID.

the class QueryEditorPart method refreshQueryOptions.

//	/**
//	 * Set query connection
//	 *
//	 * @param queryConn Connection
//	 */
//	public void setQueryConn(Connection queryConn) {
//		this.queryConn = queryConn;
//	}
/**
	 * When query options change or database and server refresh, refresh this
	 * query style
	 */
public void refreshQueryOptions() {
    CubridDatabase database = getSelectedDatabase();
    boolean enabled = (database != DatabaseNavigatorMenu.NULL_DATABASE);
    if (enabled && !connection.hasConnection()) {
        this.initConnection(database);
    }
    enabled = enabled && connection.hasConnection();
    if (enabled) {
        for (CombinedQueryEditorComposite combinedQueryEditorComposite : getAllCombinedQueryEditorComposite()) {
            combinedQueryEditorComposite.getMultiDBQueryComp().setMainDatabase(database);
        }
    }
    queryPlanItem.setEnabled(enabled);
    setPstmtParaItem.setEnabled(enabled);
    ServerInfo serverInfo = getSelectedServer() == null ? null : getSelectedServer().getServerInfo();
    String fontString = QueryOptions.getFontString(serverInfo);
    Font font = ResourceManager.getFont(fontString);
    if (font == null) {
        String[] fontData = QueryOptions.getDefaultFont();
        font = ResourceManager.getFont(fontData[0], Integer.valueOf(fontData[1]), Integer.valueOf(fontData[2]));
    }
    int[] fontColor = QueryOptions.getFontColor(serverInfo);
    final Color color = ResourceManager.getColor(fontColor[0], fontColor[1], fontColor[2]);
    // Change SQL editor font
    if (font != null) {
        getSqlTextEditor().setFont(font);
    }
    getSqlTextEditor().setForeground(color);
    for (CombinedQueryEditorComposite combinedQueryEditorComposite : getAllCombinedQueryEditorComposite()) {
        combinedQueryEditorComposite.getSqlEditorComp().getTextViewer().refresh();
        // Change the table result font
        QueryResultComposite queryResultComp = combinedQueryComposite.getQueryResultComp();
        if (queryResultComp == null || queryResultComp.isDisposed()) {
            return;
        }
        Table resultTable = queryResultComp.getResultTable();
        if (resultTable != null && !resultTable.isDisposed()) {
            resultTable.setFont(font);
            resultTable.setForeground(color);
        }
        // Update editor config
        if (database != null) {
            DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, isCMMode);
            if (editorConfig != null && editorConfig.getBackGround() != null) {
                setEditorBackground(ResourceManager.getColor(editorConfig.getBackGround()));
            } else {
                setEditorBackground(ResourceManager.getColor(EditorConstance.getDefaultBackground()));
            }
        }
        //query plan
        combinedQueryComposite.getQueryPlanResultComp().fillPlanHistory();
        //sql history
        combinedQueryComposite.getRecentlyUsedSQLComposite().fillRecentlyUsedSQLList();
        /*Fire database changed*/
        combinedQueryComposite.fireDatabaseChanged(database);
    }
}
Also used : QueryResultComposite(com.cubrid.common.ui.query.control.QueryResultComposite) Table(org.eclipse.swt.widgets.Table) CombinedQueryEditorComposite(com.cubrid.common.ui.query.control.CombinedQueryEditorComposite) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) Color(org.eclipse.swt.graphics.Color) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig) Font(org.eclipse.swt.graphics.Font)

Example 4 with CombinedQueryEditorComposite

use of com.cubrid.common.ui.query.control.CombinedQueryEditorComposite in project cubrid-manager by CUBRID.

the class InformationWindow method updateLocation.

/**
	 * Update the location
	 */
public void updateLocation() {
    int x = 0, y = 0;
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null || window.getActivePage() == null) {
        return;
    }
    Shell windowShell = this.getShell();
    if (windowShell == null) {
        InfoWindowManager.dispose();
        return;
    }
    IEditorPart editPart = window.getActivePage().getActiveEditor();
    if (editPart != null && editPart instanceof QueryEditorPart) {
        QueryEditorPart queryEditorPart = (QueryEditorPart) editPart;
        CombinedQueryEditorComposite combinedComposite = queryEditorPart.getCombinedQueryComposite();
        if (combinedComposite != null && !combinedComposite.isDisposed()) {
            Rectangle compositeBounds = combinedComposite.getBounds();
            if (compositeBounds.width < width + horizonalMargin || compositeBounds.height < height + verticalMargin) {
                windowShell.setVisible(false);
                return;
            }
            Point size = infoText.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            width = size.x;
            height = size.y;
            Point endLocation = Display.getCurrent().map(combinedComposite, null, new Point(compositeBounds.width, compositeBounds.height));
            x = endLocation.x - width - horizonalMargin;
            y = endLocation.y - height - verticalMargin;
            windowShell.setBounds(x, y, width, height);
            if (StringUtil.isEmpty(infoText.getText())) {
                windowShell.setVisible(false);
            } else {
                windowShell.setVisible(true);
            }
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Shell(org.eclipse.swt.widgets.Shell) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) CombinedQueryEditorComposite(com.cubrid.common.ui.query.control.CombinedQueryEditorComposite) Rectangle(org.eclipse.swt.graphics.Rectangle) IEditorPart(org.eclipse.ui.IEditorPart) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 5 with CombinedQueryEditorComposite

use of com.cubrid.common.ui.query.control.CombinedQueryEditorComposite in project cubrid-manager by CUBRID.

the class QueryEditorPart method addEditorTab.

public CombinedQueryEditorComposite addEditorTab() {
    final SubQueryEditorTabItem subQueryEditorTabItem = new SubQueryEditorTabItem(combinedQueryEditortabFolder, SWT.NONE);
    subQueryEditorTabItem.setTabIndex(sqlEditorCounter++);
    updateTabName(subQueryEditorTabItem, false);
    subQueryEditorTabItem.setToolTipText(Messages.queryEditorTabItemTooltip);
    subQueryEditorTabItem.setShowClose(true);
    // When clicking the close button on a tab
    subQueryEditorTabItem.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            if (!willClose && combinedQueryEditortabFolder.getItemCount() == 0) {
                sqlEditorCounter = 1;
                addEditorTab();
            }
        }
    });
    combinedQueryComposite = new CombinedQueryEditorComposite(combinedQueryEditortabFolder, SWT.None, this, subQueryEditorTabItem);
    subQueryEditorTabItem.setControl(combinedQueryComposite);
    combinedQueryComposite.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
    combinedQueryComposite.setTopSashWidth();
    combinedQueryComposite.refreshEditorComposite();
    dragController.registerDropTarget(combinedQueryComposite);
    combinedQueryEditortabFolder.setSelection(subQueryEditorTabItem);
    if (combinedQueryEditortabFolder.getItemCount() > 1) {
        InfoWindowManager.getInstance().updateContent(QueryEditorPart.this);
    }
    refreshQueryOptions();
    return combinedQueryComposite;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) CombinedQueryEditorComposite(com.cubrid.common.ui.query.control.CombinedQueryEditorComposite) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Aggregations

CombinedQueryEditorComposite (com.cubrid.common.ui.query.control.CombinedQueryEditorComposite)9 QueryEditorPart (com.cubrid.common.ui.query.editor.QueryEditorPart)4 ArrayList (java.util.ArrayList)3 Point (org.eclipse.swt.graphics.Point)3 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)2 RestorableQueryEditorInfo (com.cubrid.common.ui.spi.model.RestorableQueryEditorInfo)2 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)2 IOException (java.io.IOException)2 CTabItem (org.eclipse.swt.custom.CTabItem)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 PartInitException (org.eclipse.ui.PartInitException)2 QueryResultComposite (com.cubrid.common.ui.query.control.QueryResultComposite)1 QueryUnit (com.cubrid.common.ui.query.editor.QueryUnit)1 StatusLineContrItem (com.cubrid.common.ui.spi.contribution.StatusLineContrItem)1 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)1 DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)1 ApplicationPersistUtil (com.cubrid.common.ui.spi.persist.ApplicationPersistUtil)1 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)1 SQLException (java.sql.SQLException)1 Date (java.util.Date)1