Search in sources :

Example 66 with IWorkbenchWindow

use of org.eclipse.ui.IWorkbenchWindow in project cubrid-manager by CUBRID.

the class QueryEditorUtil method openQueryEditorAndRunQuery.

/**
	 * Open query editor and run query
	 * 
	 * @param database
	 * @param query
	 * @param isAutoRun
	 * @param isOpenInExistEditor
	 */
public static void openQueryEditorAndRunQuery(CubridDatabase database, String query, boolean isAutoRun, boolean isOpenInExistEditor) {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    QueryEditorPart queryEditor = null;
    /*Find exist query editor*/
    if (isOpenInExistEditor) {
        List<QueryEditorPart> editorPartList = getAllQueryEditorPart();
        for (QueryEditorPart editor : editorPartList) {
            if (database.equals(editor.getSelectedDatabase())) {
                queryEditor = editor;
            }
        }
    }
    boolean isNewQueryEditor = false;
    /*Open new query editor*/
    if (queryEditor == null) {
        QueryUnit input = new QueryUnit();
        input.setDatabase(database);
        try {
            queryEditor = (QueryEditorPart) window.getActivePage().openEditor(input, QueryEditorPart.ID);
            queryEditor.connect(database);
            isNewQueryEditor = true;
        } catch (PartInitException ex) {
            LOGGER.equals(ex.getMessage());
        }
    }
    /*Run query*/
    if (queryEditor != null) {
        if (isNewQueryEditor) {
            queryEditor.setQuery(query, false, isAutoRun, false);
        } else {
            queryEditor.newQueryTab(query, isAutoRun);
        }
        window.getActivePage().activate(queryEditor);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) PartInitException(org.eclipse.ui.PartInitException)

Example 67 with IWorkbenchWindow

use of org.eclipse.ui.IWorkbenchWindow in project cubrid-manager by CUBRID.

the class SqlmapNavigatorView method refreshView.

public void refreshView() {
    String queryId = getSelectedQueryId();
    List<String> condListForQuery = new ArrayList<String>();
    List<QueryCondition> condList = SqlmapPersistUtil.getInstance().getConditions(queryId);
    List<Map<String, String>> condData = new ArrayList<Map<String, String>>();
    for (QueryCondition cond : condList) {
        Map<String, String> item = new HashMap<String, String>();
        String condNameValue = cond.getConditionKey() + ":" + cond.getConditionBody();
        item.put("1", condNameValue);
        condData.add(item);
        if (SqlmapPersistUtil.getInstance().isUsedCondition(queryId, condNameValue)) {
            condListForQuery.add(condNameValue);
        }
    }
    condView.setInput(condData);
    List<Map<String, String>> paramData = new ArrayList<Map<String, String>>();
    Map<String, BindParameter> bindParams = SqlmapPersistUtil.getInstance().getBindParameters(queryId);
    for (Map.Entry<String, BindParameter> entry : bindParams.entrySet()) {
        Map<String, String> item = new HashMap<String, String>();
        item.put("0", entry.getValue().getName());
        item.put("1", entry.getValue().getValue());
        item.put("2", entry.getValue().getType().name());
        paramData.add(item);
    }
    paramView.setInput(paramData);
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    IEditorPart editorPart = window.getActivePage().getActiveEditor();
    if (!(editorPart instanceof QueryEditorPart)) {
        return;
    }
    QueryEditorPart queryEditorPart = (QueryEditorPart) editorPart;
    MapperFile mapperFile = null;
    try {
        mapperFile = new MapperParserImpl().parse(queryEditorPart.getAllQueries());
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        return;
    }
    String generatedQuery = mapperFile.generateQuery(queryId, condListForQuery);
    List<String> bindParamList = QueryUtil.extractBindParameters(mapperFile.generateRawQuery(queryId));
    for (String bindParam : bindParamList) {
        String paramRawName = bindParam;
        String paramName = QueryUtil.extractBindParameterName(paramRawName);
        BindParameter bindValue = bindParams.get(paramName);
        if (bindValue != null) {
            String value = bindValue.getType() == BindParameterType.STRING ? "'" + bindValue.getValue() + "'" : bindValue.getValue();
            generatedQuery = generatedQuery.replace(paramRawName, value);
        }
    }
    sqlView.setText(formator.format(generatedQuery));
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) MapperParserImpl(com.navercorp.dbtools.sqlmap.parser.MapperParserImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryCondition(com.navercorp.dbtools.sqlmap.parser.QueryCondition) Map(java.util.Map) HashMap(java.util.HashMap) MapperFile(com.navercorp.dbtools.sqlmap.parser.MapperFile)

Example 68 with IWorkbenchWindow

use of org.eclipse.ui.IWorkbenchWindow in project cubrid-manager by CUBRID.

the class SqlmapNavigatorView method getInstance.

/**
	 * Return current SqlmapNavigatorView instance.
	 *
	 * @return
	 */
public static SqlmapNavigatorView getInstance() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return null;
    }
    IWorkbenchPage page = window.getActivePage();
    if (page == null) {
        return null;
    }
    IViewReference viewReference = page.findViewReference(ID);
    if (viewReference != null) {
        IViewPart viewPart = viewReference.getView(false);
        return viewPart instanceof SqlmapNavigatorView ? (SqlmapNavigatorView) viewPart : null;
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Example 69 with IWorkbenchWindow

use of org.eclipse.ui.IWorkbenchWindow in project cubrid-manager by CUBRID.

the class SqlmapNavigatorView method pasteSqlToQueryEditor.

private void pasteSqlToQueryEditor(String sql) {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null || window.getActivePage() == null) {
        return;
    }
    IEditorPart editor = window.getActivePage().getActiveEditor();
    try {
        if (editor == null || !(editor instanceof QueryEditorPart)) {
            editor = window.getActivePage().openEditor(new QueryUnit(), QueryEditorPart.ID);
        }
    } catch (PartInitException e) {
        editor = null;
    }
    if (editor == null) {
        return;
    }
    QueryEditorPart queryEditor = (QueryEditorPart) editor;
    if (!StringUtil.isEmpty(queryEditor.getCurrentQuery())) {
        queryEditor.addEditorTab();
    }
    queryEditor.setQuery(sql, false, false, false);
    queryEditor.setFocus();
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException)

Example 70 with IWorkbenchWindow

use of org.eclipse.ui.IWorkbenchWindow in project cubrid-manager by CUBRID.

the class BrokerEnvStatusView method createTable.

/**
	 * This method initializes table
	 *
	 */
private void createTable() {
    tableViewer = new TableViewer(composite, SWT.FULL_SELECTION);
    tableViewer.getTable().setHeaderVisible(true);
    tableViewer.getTable().setLinesVisible(true);
    BrokerTblColumnSetHelp bcsh = BrokerTblColumnSetHelp.getInstance();
    bcsh.loadSetting(BrokerTblColumnSetHelp.StatusColumn.BrokerEnvStatusColumn, BrokerEnvStatusColumn.values());
    TableLayout tlayout = new TableLayout();
    for (BrokerEnvStatusColumn column : BrokerEnvStatusColumn.values()) {
        if (column.getValue() == -1) {
            tlayout.addColumnData(new ColumnWeightData(0, 0, false));
        } else {
            tlayout.addColumnData(new ColumnWeightData(10, 40, true));
        }
    }
    tableViewer.getTable().setLayout(tlayout);
    tableViewer.getTable().addMouseListener(new MouseAdapter() {

        public void mouseDoubleClick(MouseEvent event) {
            int index = -1;
            if ((index = tableViewer.getTable().getSelectionIndex()) >= 0) {
                TableItem tableItem = tableViewer.getTable().getItem(index);
                String brokename = tableItem.getText(0).trim();
                ICubridNode input = null;
                for (ICubridNode node : cubridNode.getChildren()) {
                    if (node.getLabel().equalsIgnoreCase(brokename)) {
                        input = node;
                        break;
                    }
                }
                LayoutManager.getInstance().setCurrentSelectedNode(input);
                IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                if (null == window) {
                    return;
                }
                IWorkbenchPage activePage = window.getActivePage();
                IViewPart viewPart = window.getActivePage().findView(BrokerStatusView.ID);
                if (null != viewPart) {
                    activePage.hideView(viewPart);
                }
                try {
                    activePage.showView(BrokerStatusView.ID);
                } catch (PartInitException e1) {
                    LOGGER.error(e1.getMessage(), e1);
                }
            }
        }
    });
    makeTableColumn();
    tableViewer.setContentProvider(new BrokersStatusContentProvider());
    ServerInfo serverInfo = cubridNode.getServer().getServerInfo();
    BrokersStatusLabelProvider brokersStatusLabelProvider = new BrokersStatusLabelProvider();
    brokersStatusLabelProvider.setServerInfo(serverInfo);
    tableViewer.setLabelProvider(brokersStatusLabelProvider);
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) MouseEvent(org.eclipse.swt.events.MouseEvent) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) TableItem(org.eclipse.swt.widgets.TableItem) MouseAdapter(org.eclipse.swt.events.MouseAdapter) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) BrokerEnvStatusColumn(com.cubrid.cubridmanager.ui.broker.editor.internal.BrokerEnvStatusColumn) BrokerTblColumnSetHelp(com.cubrid.cubridmanager.ui.broker.editor.internal.BrokerTblColumnSetHelp) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) TableViewer(org.eclipse.jface.viewers.TableViewer) TableLayout(org.eclipse.jface.viewers.TableLayout)

Aggregations

IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)363 IEditorPart (org.eclipse.ui.IEditorPart)136 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)102 PartInitException (org.eclipse.ui.PartInitException)81 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)41 QueryEditorPart (com.cubrid.common.ui.query.editor.QueryEditorPart)39 IViewPart (org.eclipse.ui.IViewPart)39 ArrayList (java.util.ArrayList)37 IEditorReference (org.eclipse.ui.IEditorReference)35 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)32 IWorkbench (org.eclipse.ui.IWorkbench)32 IFile (org.eclipse.core.resources.IFile)30 ISelection (org.eclipse.jface.viewers.ISelection)29 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)27 Shell (org.eclipse.swt.widgets.Shell)26 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)24 CoreException (org.eclipse.core.runtime.CoreException)23 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)21 IProject (org.eclipse.core.resources.IProject)20 QueryUnit (com.cubrid.common.ui.query.editor.QueryUnit)19