use of com.cubrid.common.ui.spi.model.ISchemaNode in project cubrid-manager by CUBRID.
the class QueryTunerAction method run.
public void run() {
Object[] obj = this.getSelectedObj();
if (!isSupported(obj)) {
setEnabled(false);
return;
}
ISelectionProvider provider = getSelectionProvider();
if (!(provider instanceof TreeViewer)) {
return;
}
ISchemaNode node = (ISchemaNode) obj[0];
String query = getQuery();
if (StringUtil.isNotEmpty(query)) {
new QueryTunerDialog(getShell(), node.getDatabase(), query).open();
} else {
CommonUITool.openInformationBox(Messages.errSelectQueryForTuning);
new QueryTunerDialog(getShell(), node.getDatabase()).open();
}
}
use of com.cubrid.common.ui.spi.model.ISchemaNode in project cubrid-manager by CUBRID.
the class QueryEditorDNDController method replaceSql.
/**
* Replace the SQL
*
* @return boolean
*/
private boolean replaceSql() {
// FIXME move this logic to core module
List<ISchemaNode> schemaNodeList = new ArrayList<ISchemaNode>();
Map<String, List<ISchemaNode>> columnNodeMap = new HashMap<String, List<ISchemaNode>>();
boolean isValid = fillInSelectedNode(schemaNodeList, columnNodeMap);
if (!isValid || (schemaNodeList.isEmpty() && columnNodeMap.isEmpty())) {
return false;
}
//Confirm whether change database connection
CubridDatabase db = null;
for (ISchemaNode selectedNode : schemaNodeList) {
db = selectedNode.getDatabase();
break;
}
if (db == null) {
Iterator<List<ISchemaNode>> it = columnNodeMap.values().iterator();
while (it.hasNext()) {
db = it.next().get(0).getDatabase();
break;
}
}
if (db == null) {
return false;
}
CubridDatabase selectedDb = editor.getSelectedDatabase();
if (!selectedDb.getId().equals(db.getId())) {
int returnVal = openConfirmDialog();
if (returnVal == 2 || returnVal == -1) {
return false;
}
if (editor.isTransaction() && returnVal == 0 && !openTransactionDialog(selectedDb)) {
return false;
}
if (returnVal == 0) {
editor.shutDownConnection();
editor.connect(db);
}
}
//Get all table SQL
StringBuilder sqlBuffer = new StringBuilder();
for (ISchemaNode selectedNode : schemaNodeList) {
String sql = getScript(selectedNode);
if (sql != null) {
sqlBuffer.append(sql);
}
}
//Get the selected columns SQL
Iterator<Map.Entry<String, List<ISchemaNode>>> it = columnNodeMap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, List<ISchemaNode>> entry = it.next();
String sql = getScript(entry.getKey(), entry.getValue());
if (sql != null) {
sqlBuffer.append(sql);
}
}
if (sqlBuffer.length() > 0) {
String sql = sqlBuffer.toString();
int originalQueryLength = editor.getAllQueries().length();
int newQueryLength = sql.length();
int caretOffset = editor.getSqlEditorWidget().getCaretOffset();
if (originalQueryLength > 0 && caretOffset >= 0) {
String pre = editor.getAllQueries().substring(0, caretOffset);
String post = editor.getAllQueries().substring(caretOffset, editor.getAllQueries().length());
editor.getSqlEditorWidget().setText(pre + sql + post);
editor.getSqlEditorWidget().setSelection(caretOffset);
} else {
editor.setQuery(sql, true, false, false);
int endIndexOfSelection = originalQueryLength + newQueryLength;
editor.setSelection(originalQueryLength, endIndexOfSelection);
}
ActionManager.getInstance().changeFocusProvider(editor.getSqlEditorWidget());
return true;
}
return false;
}
use of com.cubrid.common.ui.spi.model.ISchemaNode in project cubrid-manager by CUBRID.
the class QueryNewAction method getSelectedSever.
/**
* Get current selected server
*
* @return CubridServer
*/
private CubridServer getSelectedSever() {
Object[] selected = getSelectedObj();
CubridServer server = null;
if (selected != null && selected.length >= 1) {
if (selected[0] instanceof ISchemaNode) {
server = ((ISchemaNode) selected[0]).getServer();
} else if (selected[0] instanceof ICubridNode) {
server = ((ICubridNode) selected[0]).getServer();
}
}
return server;
}
use of com.cubrid.common.ui.spi.model.ISchemaNode in project cubrid-manager by CUBRID.
the class QueryNewAction method handleSelectionObj.
/**
* handleSelectionObj
* @param objs
* @return
*/
private CubridDatabase[] handleSelectionObj(Object[] objs) {
List<CubridDatabase> returnArray = new ArrayList<CubridDatabase>();
CubridDatabase database = null;
for (Object obj : objs) {
if (obj instanceof ISchemaNode) {
database = ((ISchemaNode) obj).getDatabase();
if (database != null) {
//if multiple selection ,only open a query editor with one database
if (!returnArray.contains(database)) {
returnArray.add(database);
}
}
}
}
return returnArray.toArray(new CubridDatabase[0]);
}
use of com.cubrid.common.ui.spi.model.ISchemaNode in project cubrid-manager by CUBRID.
the class QueryNewCustomAction method run.
/**
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
Object[] selected = getSelectedObj();
LoginQueryEditDialog dialog = new LoginQueryEditDialog(getShell());
if (selected != null && selected.length == 1 && selected[0] instanceof ISchemaNode) {
dialog.setSelServerName(((ISchemaNode) selected[0]).getServer().getServerName());
dialog.setSelDatabaseName(((ISchemaNode) selected[0]).getDatabase().getName());
} else if (selected != null && selected.length == 1 && selected[0] instanceof CubridServer) {
dialog.setSelServerName(((CubridServer) selected[0]).getName());
} else {
dialog.setSelServerName(DatabaseNavigatorMenu.SELF_DATABASE_SELECTED_LABEL);
}
if (dialog.open() == IDialogConstants.OK_ID) {
try {
IEditorInput input = new QueryUnit();
IEditorPart editor = window.getActivePage().openEditor(input, QueryEditorPart.ID);
((QueryEditorPart) editor).connect(DatabaseNavigatorMenu.SELF_DATABASE);
} catch (PartInitException e) {
LOGGER.error(e.getMessage());
}
}
}
Aggregations