use of com.cubrid.common.ui.spi.model.ICubridNode in project cubrid-manager by CUBRID.
the class CubridNavigatorView method addListener.
/**
*
* Add listener
*
*/
protected void addListener() {
tv.getTree().addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent event) {
if (toolTip.isVisible()) {
toolTip.setVisible(false);
}
}
public void mouseUp(MouseEvent event) {
if (event.button == 1 && LayoutManager.getInstance().isUseClickOnce()) {
ISelection selection = tv.getSelection();
if (selection == null || selection.isEmpty()) {
return;
}
Object obj = ((IStructuredSelection) selection).getFirstElement();
if (!(obj instanceof ICubridNode)) {
return;
}
ICubridNode cubridNode = (ICubridNode) obj;
LayoutManager.getInstance().getWorkbenchContrItem().openEditorOrView(cubridNode);
}
}
});
tv.getTree().addMouseTrackListener(new MouseTrackAdapter() {
public void mouseHover(MouseEvent event) {
if (toolTip.isVisible()) {
toolTip.setVisible(false);
}
int x = event.x;
int y = event.y;
TreeItem item = tv.getTree().getItem(new Point(x, y));
if (item == null) {
return;
}
showToolTip(item);
}
});
tv.getTree().addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent event) {
widgetSelected(event);
}
public void widgetSelected(SelectionEvent event) {
if (toolTip.isVisible()) {
toolTip.setVisible(false);
}
TreeItem[] items = tv.getTree().getSelection();
if (items == null || items.length == 0) {
return;
}
showToolTip(items[0]);
if (items.length == 1) {
showSchemaInfo(items[0]);
} else {
showSchemaInfo(null);
}
}
});
addDragDropSupport(tv.getTree());
tv.getTree().addKeyListener(new KeyListener() {
public void keyReleased(KeyEvent e) {
}
public void keyPressed(KeyEvent e) {
// prevent to make events by key press for a long time
if (e.character == ' ') {
TreeItem[] items = tv.getTree().getSelection();
if (items == null || items.length == 0) {
return;
}
if (items.length == 1) {
showSchemaInfo(items[0]);
} else {
showSchemaInfo(null);
}
}
lastKeyInputTimestamp = System.currentTimeMillis();
// by showing object information tab on the query editor.
if (e.keyCode == SWT.F2) {
TreeItem[] items = tv.getTree().getSelection();
if (items == null || items.length == 0) {
return;
}
for (TreeItem item : items) {
Object obj = item.getData();
if (obj instanceof ICubridNode) {
ICubridNode node = (ICubridNode) obj;
if (NodeType.USER_TABLE.equals(node.getType()) || NodeType.SYSTEM_TABLE.equals(node.getType()) || NodeType.USER_VIEW.equals(node.getType()) || NodeType.SYSTEM_VIEW.equals(node.getType())) {
DefaultSchemaNode table = (DefaultSchemaNode) obj;
OpenTargetAction action = new OpenTargetAction();
action.showObjectInfo(table);
} else if (NodeType.TABLE_FOLDER.equals(node.getType())) {
CubridNavigatorView view = CubridNavigatorView.getNavigatorView(ID_CQB);
if (view == null) {
view = CubridNavigatorView.getNavigatorView(ID_CM);
}
if (view == null) {
return;
}
TreeViewer treeViewer = view.getViewer();
//if not expand ,expand the node and wait until all children be added
if (!treeViewer.getExpandedState(node)) {
treeViewer.expandToLevel(node, 1);
while (node.getChildren().size() == 0) {
try {
Thread.sleep(500);
} catch (Exception ignored) {
}
}
}
CubridDatabase database = (CubridDatabase) node.getParent();
OpenTargetAction action = new OpenTargetAction();
action.showTableDashboard(database);
}
}
}
}
}
});
}
use of com.cubrid.common.ui.spi.model.ICubridNode in project cubrid-manager by CUBRID.
the class ExportObjectLabelProvider method update.
/**
* update
*
* @param cell ViewerCell
*/
public void update(ViewerCell cell) {
if (cell.getColumnIndex() == 0) {
if (cell.getElement() instanceof ICubridNode) {
ICubridNode node = (ICubridNode) cell.getElement();
cell.setImage(CommonUIPlugin.getImage(node.getIconPath()));
cell.setText(node.getName());
} else if (cell.getElement() instanceof PendingUpdateAdapter) {
cell.setText(Messages.msgLoading);
}
} else if (cell.getColumnIndex() == 1 && cell.getElement() instanceof ICubridNode) {
ICubridNode node = (ICubridNode) cell.getElement();
String condition = (String) node.getData(CONDITION);
if (condition != null) {
cell.setText(condition);
}
// cell can't edit ,set it to gray color
if (node.getType().equals(NodeType.TABLE_COLUMN)) {
cell.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
}
}
}
use of com.cubrid.common.ui.spi.model.ICubridNode in project cubrid-manager by CUBRID.
the class CubridDeferredTreeContentManager method addChildren.
/**
* Create a UIJob to add the children to the parent in the tree viewer.
*
* @param parent the parent tree container node
* @param children the added children array
* @param monitor the monitor object
*/
protected void addChildren(final Object parent, final Object[] children, IProgressMonitor monitor) {
WorkbenchJob updateJob = new WorkbenchJob(Messages.msgAddingChildren) {
public IStatus runInUIThread(IProgressMonitor updateMonitor) {
// Cancel the job if the tree viewer got closed
if (treeViewer.getControl().isDisposed() || updateMonitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
treeViewer.add(parent, children);
if (parent instanceof ICubridNode && ((ICubridNode) parent).isContainer()) {
treeViewer.update(parent, null);
ActionManager.getInstance().fireSelectionChanged(treeViewer.getSelection());
}
ICubridNode parentNode = null;
if (parent instanceof ICubridNode) {
parentNode = (ICubridNode) parent;
}
boolean isExpandNextLevel = parentNode != null && (parentNode.getType().equals(NodeType.USER_TABLE) || parentNode.getType().equals(NodeType.SERVER)) && expandedElements == null;
if (isExpandNextLevel) {
expandToNextLevel(children);
} else {
for (int i = 0; children != null && i < children.length; i++) {
if ((children[i] instanceof ICubridNode)) {
ICubridNode node = (ICubridNode) children[i];
for (int j = 0; expandedElements != null && j < expandedElements.length; j++) {
if (expandedElements[j] instanceof ICubridNode && node.getId().equals(((ICubridNode) expandedElements[j]).getId())) {
treeViewer.expandToLevel(children[i], 1);
}
}
}
}
}
// set user/table folder node label, add children count
if (hasChildCount(parentNode)) {
int count = 0;
if (parentNode.getType().equals(NodeType.TABLE_FOLDER)) {
count = 0;
for (ICubridNode tableNode : parentNode.getChildren()) {
if (tableNode.getType().equals(NodeType.USER_TABLE) || tableNode.getType().equals(NodeType.USER_PARTITIONED_TABLE_FOLDER)) {
count++;
}
}
} else if (parentNode.getType().equals(NodeType.VIEW_FOLDER)) {
for (ICubridNode viewNode : parentNode.getChildren()) {
if (viewNode.getType().equals(NodeType.USER_VIEW)) {
count++;
}
}
} else {
count = parentNode.getChildren().size();
}
String suffix = "(" + Integer.valueOf(count) + ")";
String beforeLable = parentNode.getLabel();
if (beforeLable.endsWith(")") && beforeLable.indexOf("(") > -1) {
String beforeCount = beforeLable.substring(beforeLable.indexOf("(") + 1, beforeLable.length() - 1);
// if children count not change, do not update label
if (String.valueOf(count).equals(beforeCount)) {
return Status.OK_STATUS;
}
beforeLable = beforeLable.substring(0, beforeLable.indexOf("("));
}
parentNode.setLabel(beforeLable + suffix);
treeViewer.refresh(parentNode, true);
}
return Status.OK_STATUS;
}
};
updateJob.setSystem(true);
updateJob.schedule();
}
use of com.cubrid.common.ui.spi.model.ICubridNode in project cubrid-manager by CUBRID.
the class CubridDeferredTreeContentManager method expandToNextLevel.
/**
* Expand to next level
*
* @param children Object[]
*/
private void expandToNextLevel(final Object[] children) {
for (int i = 0; children != null && i < children.length; i++) {
ICubridNode node = null;
if (children[i] instanceof ICubridNode) {
node = (ICubridNode) children[i];
}
if (node != null && node.getType().equals(NodeType.TABLE_INDEX_FOLDER)) {
continue;
}
treeViewer.expandToLevel(children[i], 1);
}
}
use of com.cubrid.common.ui.spi.model.ICubridNode in project cubrid-manager by CUBRID.
the class GroupSettingDialog method refreshDefaultNode.
/**
* Refresh the default node's children.
*
*/
private void refreshDefaultNode() {
java.util.List<ICubridNode> nodeWithParent = new ArrayList<ICubridNode>();
CubridGroupNode defaultGrp = null;
for (CubridGroupNode grp : groups) {
if (nodeManager.isDefaultGroup(grp)) {
defaultGrp = grp;
} else {
nodeWithParent.addAll(grp.getChildren());
}
}
if (defaultGrp == null) {
LOGGER.warn("The defaultGrp is a null.");
return;
}
defaultGrp.removeAllChild();
java.util.List<ICubridNode> allItems = nodeManager.getAllGroupItems();
for (ICubridNode item : allItems) {
if (nodeWithParent.indexOf(item) < 0) {
defaultGrp.addChild(item);
}
}
}
Aggregations