use of org.eclipse.jface.viewers.StructuredSelection in project cubrid-manager by CUBRID.
the class ERSchemaEditor method searchAndLocate.
/**
* Set matched tables to be selected, and next(or first) finding table to be
* focused
*
* @param keyWord
* @param isChangedKey
* @return
*/
public boolean searchAndLocate(String keyWord, boolean isChangedKey) {
SchemaDiagramPart schemaRootPart = getERSchemaRootPart();
List allParts = schemaRootPart.getChildren();
// set next focus table(focus circularly )
if (!isChangedKey && graphicalViewer.getFocusEditPart() instanceof TablePart) {
TablePart focusedTablePart = (TablePart) graphicalViewer.getFocusEditPart();
int preFocusIndex = allParts.indexOf(focusedTablePart);
int start = preFocusIndex + 1;
for (; start < allParts.size(); start++) {
Object table = allParts.get(start);
if (table instanceof TablePart) {
TablePart nexFocusTable = (TablePart) table;
if (nexFocusTable.getTable().getShownName().contains(keyWord)) {
getViewPort().setViewLocation(nexFocusTable.getFigure().getBounds().x, nexFocusTable.getFigure().getBounds().y);
graphicalViewer.setFocus(nexFocusTable);
return true;
}
}
if (start == allParts.size()) {
start = 0;
}
}
}
// set first focus table and gray tables
Iterator it = allParts.iterator();
List matchedList = new ArrayList();
boolean isFocus = false;
while (it.hasNext()) {
Object obj = it.next();
if (!(obj instanceof TablePart)) {
continue;
}
TablePart tablePart = (TablePart) obj;
ERTable erTable = tablePart.getTable();
if (erTable.getShownName().contains(keyWord)) {
matchedList.add(tablePart);
if (!isFocus) {
getViewPort().setViewLocation(tablePart.getFigure().getBounds().x, tablePart.getFigure().getBounds().y);
graphicalViewer.setFocus(tablePart);
isFocus = true;
}
} else {
TableFigure figure = (TableFigure) tablePart.getFigure();
figure.setDisabled(true);
}
}
StructuredSelection matchedTables = new StructuredSelection(matchedList);
graphicalViewer.setSelection(matchedTables);
return true;
}
use of org.eclipse.jface.viewers.StructuredSelection in project cubrid-manager by CUBRID.
the class CommonUITool method addNodeToTree.
/**
*
* Add new node to parent node in model and add this node to tree
*
* @param viewer The TreeViewer
* @param parent The parent node
* @param node The added node
*/
public static void addNodeToTree(TreeViewer viewer, ICubridNode parent, ICubridNode node) {
if (parent == null || node == null) {
return;
}
parent.addChild(node);
viewer.insert(parent, node, parent.position(node));
viewer.setSelection(new StructuredSelection(node), true);
}
use of org.eclipse.jface.viewers.StructuredSelection in project cubrid-manager by CUBRID.
the class DeleteDatabaseAction method run.
public void run() {
Object[] obj = this.getSelectedObj();
if (!isSupported(obj[0])) {
setEnabled(false);
return;
}
ISelectionProvider provider = this.getSelectionProvider();
if (!(provider instanceof TreeViewer)) {
return;
}
ISchemaNode node = (ISchemaNode) obj[0];
CubridDatabase database = node.getDatabase();
if (database == null) {
CommonUITool.openErrorBox(getShell(), Messages.msgSelectDB);
return;
}
CommonQueryTask<DbSpaceInfoList> task = new CommonQueryTask<DbSpaceInfoList>(database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), new DbSpaceInfoList());
task.setDbName(database.getName());
TaskExecutor taskExcutor = new CommonTaskExec(Messages.getDbSpaceInfoTaskName);
taskExcutor.addTask(task);
new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
if (!taskExcutor.isSuccess()) {
return;
}
DeleteDatabaseDialog dlg = new DeleteDatabaseDialog(getShell());
dlg.setDbSpaceInfo(task.getResultModel());
dlg.setDatabase(database);
ICubridNode parent = database.getParent();
if (dlg.open() == DeleteDatabaseDialog.DELETE_ID) {
boolean isContinue = DatabaseUtils.processDatabaseDeleted(database);
if (isContinue) {
TreeViewer viewer = (TreeViewer) provider;
parent.removeChild(database);
viewer.remove(parent, obj);
viewer.setSelection(new StructuredSelection(parent));
}
}
}
use of org.eclipse.jface.viewers.StructuredSelection in project cubrid-manager by CUBRID.
the class PasteQueryConnAction method run.
/**
* Paste the query connection
*/
public void run() {
Object[] objs = this.getSelectedObj();
if (!isSupported(objs[0])) {
setEnabled(false);
return;
}
objs = null;
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection strSelection = (IStructuredSelection) selection;
objs = strSelection.toArray();
}
if (objs == null || objs.length == 0) {
return;
}
if (!(objs[0] instanceof CubridDatabase)) {
return;
}
CubridDatabase pastedDb = (CubridDatabase) objs[0];
QueryConnDialog dialog = new QueryConnDialog(getShell(), pastedDb, true);
int returnCode = dialog.open();
if (returnCode == QueryConnDialog.CONNECT_ID || returnCode == QueryConnDialog.SAVE_ID) {
CubridDatabase database = dialog.getDatabase();
CQBDBNodePersistManager.getInstance().addDatabase(database, false);
CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridQueryNavigatorView.ID);
TreeViewer treeViewer = navigatorView == null ? null : navigatorView.getViewer();
if (treeViewer == null) {
return;
}
Tree tree = treeViewer.getTree();
TreeItem item;
CubridGroupNode parent = getParentGroupNode();
if (navigatorView.isShowGroup()) {
item = new TreeItem(navigatorView.getTreeItemByData(parent), SWT.NONE);
} else {
item = new TreeItem(tree, SWT.NONE);
}
parent.addChild(database);
CQBGroupNodePersistManager.getInstance().saveAllGroupNode();
item.setText(database.getLabel());
item.setData(database);
treeViewer.refresh(database, true);
treeViewer.expandToLevel(database, 1);
treeViewer.setSelection(new StructuredSelection(database), true);
if (returnCode == QueryConnDialog.CONNECT_ID) {
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGIN));
}
}
}
use of org.eclipse.jface.viewers.StructuredSelection in project cubrid-manager by CUBRID.
the class CreateConnectionByUrlWizard method performFinish.
/**
* Perform finish
*/
public boolean performFinish() {
List<CubridDatabase> parsedDatabaseList = connectionPriviewPage.getParsedConnection();
/*Add the database list to the tree*/
CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridQueryNavigatorView.ID);
TreeViewer treeViewer = navigatorView == null ? null : navigatorView.getViewer();
if (treeViewer == null) {
return false;
}
for (CubridDatabase database : parsedDatabaseList) {
CQBDBNodePersistManager.getInstance().addDatabase(database, false);
Tree tree = treeViewer.getTree();
TreeItem item;
CubridGroupNode parent = CQBGroupNodePersistManager.getInstance().getDefaultGroup();
if (navigatorView.isShowGroup()) {
item = new TreeItem(navigatorView.getTreeItemByData(parent), SWT.NONE);
} else {
item = new TreeItem(tree, SWT.NONE);
}
parent.addChild(database);
item.setText(database.getLabel());
item.setData(database);
treeViewer.refresh(database, true);
treeViewer.expandToLevel(database, 1);
treeViewer.setSelection(new StructuredSelection(database), true);
}
CQBGroupNodePersistManager.getInstance().saveAllGroupNode();
return true;
}
Aggregations