Search in sources :

Example 46 with StyledText

use of org.eclipse.swt.custom.StyledText in project cubrid-manager by CUBRID.

the class RedoAction method focusGained.

/**
	 * Notifies that the focus gained event
	 * 
	 * @param event an event containing information about the focus change
	 */
public void focusGained(FocusEvent event) {
    setEnabled(false);
    if (event.getSource() instanceof StyledText) {
        StyledText stext = (StyledText) event.getSource();
        Object obj = stext.getData(SQLEditorComposite.SQL_EDITOR_FLAG);
        boolean isEnabled = obj instanceof TextViewer;
        if (isEnabled) {
            TextViewer viewer = (TextViewer) obj;
            isEnabled = viewer.getUndoManager() != null && viewer.getUndoManager().redoable();
        }
        setEnabled(isEnabled);
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) TextViewer(org.eclipse.jface.text.TextViewer)

Example 47 with StyledText

use of org.eclipse.swt.custom.StyledText in project cubrid-manager by CUBRID.

the class RunQueryAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    Control control = getFocusProvider();
    if (!(control instanceof StyledText)) {
        showNoSelectionQueryError();
        return;
    }
    StyledText stext = (StyledText) control;
    String data = stext.getSelectionText();
    if (StringUtil.isEmpty(data)) {
        showNoSelectionQueryError();
        return;
    }
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        showNoSelectionQueryError();
        return;
    }
    IEditorPart editor = window.getActivePage().getActiveEditor();
    if (editor == null || !(editor instanceof QueryEditorPart)) {
        showNoSelectionQueryError();
        return;
    }
    ((QueryEditorPart) editor).runQuery(false);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Control(org.eclipse.swt.widgets.Control) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) StyledText(org.eclipse.swt.custom.StyledText) IEditorPart(org.eclipse.ui.IEditorPart)

Example 48 with StyledText

use of org.eclipse.swt.custom.StyledText in project cubrid-manager by CUBRID.

the class RunQueryPlanAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    Control control = getFocusProvider();
    if (!(control instanceof StyledText)) {
        showNoSelectionQueryError();
        return;
    }
    StyledText stext = (StyledText) control;
    String data = stext.getSelectionText();
    if (StringUtil.isEmpty(data)) {
        showNoSelectionQueryError();
        return;
    }
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        showNoSelectionQueryError();
        return;
    }
    IEditorPart editor = window.getActivePage().getActiveEditor();
    if (editor == null || !(editor instanceof QueryEditorPart)) {
        showNoSelectionQueryError();
        return;
    }
    ((QueryEditorPart) editor).runQuery(true);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Control(org.eclipse.swt.widgets.Control) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) StyledText(org.eclipse.swt.custom.StyledText) IEditorPart(org.eclipse.ui.IEditorPart)

Example 49 with StyledText

use of org.eclipse.swt.custom.StyledText in project cubrid-manager by CUBRID.

the class QueryTunerAction method getQuery.

public String getQuery() {
    // FIXME extract to utility
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (null == window) {
        return null;
    }
    IEditorPart editor = window.getActivePage().getActiveEditor();
    if (editor == null) {
        return null;
    }
    if (!(editor instanceof QueryEditorPart)) {
        return null;
    }
    QueryEditorPart queryEditorPart = (QueryEditorPart) editor;
    StyledText stext = queryEditorPart.getSqlEditorWidget();
    return stext.getSelectionText();
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) StyledText(org.eclipse.swt.custom.StyledText) IEditorPart(org.eclipse.ui.IEditorPart)

Example 50 with StyledText

use of org.eclipse.swt.custom.StyledText in project cubrid-manager by CUBRID.

the class QueryEditorPart method runQueryInCursorLine.

/**
	 * Run the the SQL which cursor position
	 */
public void runQueryInCursorLine() {
    if (!isConnected()) {
        CommonUITool.openErrorBox(Messages.qedit_tip_run_query);
        return;
    }
    String queries = combinedQueryComposite.getSqlEditorComp().getSelectedQueries();
    if (StringUtil.isEmpty(queries)) {
        return;
    }
    try {
        connection.getConnection(true);
    } catch (SQLException e) {
        CommonUITool.openErrorBox(e.getLocalizedMessage());
        return;
    }
    if (!connection.hasConnection()) {
        return;
    }
    // TODO #644 extend to parse xml queries on the cursor location
    SQLDocument document = combinedQueryComposite.getSqlEditorComp().getDocument();
    StyledText sqlText = getSqlTextEditor();
    // get cursor position offset
    int cursorOffset = sqlText.getCaretOffset();
    // get cursor position line
    int lineNumber = sqlText.getLineAtOffset(cursorOffset);
    // get cursor position line first char offset
    int firstCharOffset = sqlText.getOffsetAtLine(lineNumber);
    if (firstCharOffset > 0) {
        firstCharOffset = firstCharOffset - 1;
    }
    int sqlStartPos = getQuerySQLStartPos(document, queries, firstCharOffset);
    String query = getQuery(queries, sqlStartPos);
    sqlText.setSelectionRange(sqlStartPos, query.length());
    runQuery(false, query.trim(), null);
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) SQLException(java.sql.SQLException) Point(org.eclipse.swt.graphics.Point)

Aggregations

StyledText (org.eclipse.swt.custom.StyledText)329 Point (org.eclipse.swt.graphics.Point)102 GridData (org.eclipse.swt.layout.GridData)68 Composite (org.eclipse.swt.widgets.Composite)63 GridLayout (org.eclipse.swt.layout.GridLayout)62 Control (org.eclipse.swt.widgets.Control)46 SelectionEvent (org.eclipse.swt.events.SelectionEvent)32 Label (org.eclipse.swt.widgets.Label)32 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)30 Display (org.eclipse.swt.widgets.Display)30 Shell (org.eclipse.swt.widgets.Shell)30 Rectangle (org.eclipse.swt.graphics.Rectangle)27 Color (org.eclipse.swt.graphics.Color)25 FillLayout (org.eclipse.swt.layout.FillLayout)25 Button (org.eclipse.swt.widgets.Button)23 Text (org.eclipse.swt.widgets.Text)21 StyleRange (org.eclipse.swt.custom.StyleRange)20 Font (org.eclipse.swt.graphics.Font)20 Event (org.eclipse.swt.widgets.Event)20 Test (org.junit.Test)20