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);
}
}
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);
}
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);
}
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();
}
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);
}
Aggregations