use of org.eclipse.swt.widgets.TreeItem in project cubrid-manager by CUBRID.
the class CubridNavigatorView method setFocus.
/**
* Call this method when focus
*/
public void setFocus() {
if (tv == null || tv.getControl() == null || tv.getControl().isDisposed()) {
return;
}
tv.getControl().setFocus();
// select the first element by default
int count = tv.getTree().getSelectionCount();
TreeItem[] items = tv.getTree().getItems();
if (count == 0 && items != null && items.length > 0) {
tv.getTree().select(items[0]);
}
ActionManager.getInstance().changeSelectionProvider(tv);
LayoutManager.getInstance().changeSelectionProvider(tv);
CubridNodeManager.getInstance().addCubridNodeChangeListener(LayoutManager.getInstance());
}
use of org.eclipse.swt.widgets.TreeItem 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 org.eclipse.swt.widgets.TreeItem in project cubrid-manager by CUBRID.
the class FavoriteQueryNavigatorView method getCurrentDatabase.
/**
* Return current selected database from the navigation tree.
* @return CubridDatabase
*/
private CubridDatabase getCurrentDatabase() {
CubridDatabase cubridDatabase = null;
CubridNavigatorView nav = CubridNavigatorView.findNavigationView();
if (nav != null) {
TreeItem[] items = nav.getSelectedItems();
if (items.length > 0 && items[0] != null && items[0].getData() instanceof ISchemaNode) {
ISchemaNode node = (ISchemaNode) items[0].getData();
CubridDatabase tempDatabase = node.getDatabase();
if (tempDatabase != null && tempDatabase.isLogined()) {
cubridDatabase = tempDatabase;
}
}
}
return cubridDatabase;
}
use of org.eclipse.swt.widgets.TreeItem in project cubrid-manager by CUBRID.
the class OIDNavigatorDialog method find.
/**
*
* Execute to find result
*
* @return <code>true</code> if it is found;<code>false</code>otherwise
*/
public boolean find() {
boolean isOk = true;
resultTree.removeAll();
TreeItem root = new TreeItem(resultTree, SWT.NONE);
isOk = searchOID(oidValueText.getText(), root);
if (!root.isDisposed()) {
root.setExpanded(true);
}
if (!resultTree.isDisposed()) {
resultTree.layout(true);
}
return isOk;
}
use of org.eclipse.swt.widgets.TreeItem in project cubrid-manager by CUBRID.
the class OIDNavigatorDialog method createDialogArea.
/**
* Create dialog area content
*
* @param parent the parent composite
* @return the control
*/
protected Control createDialogArea(Composite parent) {
Composite parentComp = (Composite) super.createDialogArea(parent);
Composite composite = new Composite(parentComp, SWT.NONE);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
GridLayout layout = new GridLayout();
layout.numColumns = 5;
layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
composite.setLayout(layout);
Label oidValueLabel = new Label(composite, SWT.LEFT);
oidValueLabel.setText(Messages.lblOIDValue);
oidValueLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
oidValueText = new Text(composite, SWT.LEFT | SWT.BORDER);
oidValueText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 3, 1, -1, -1));
if (oidStr != null) {
oidValueText.setText(oidStr);
}
oidValueText.addModifyListener(this);
findButton = new Button(composite, SWT.CENTER);
findButton.setText(Messages.btnFind);
findButton.setLayoutData(CommonUITool.createGridData(1, 1, 60, -1));
if (oidStr == null || oidStr.trim().length() <= 0) {
findButton.setEnabled(false);
}
findButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
find();
}
});
Composite findResultComp = new Composite(composite, SWT.BORDER);
findResultComp.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 5, 1, -1, 200));
findResultComp.setLayout(new GridLayout());
resultTree = new Tree(findResultComp, SWT.NONE | SWT.VIRTUAL);
GridData data = new GridData(GridData.FILL_BOTH);
resultTree.setLayoutData(data);
resultTree.addTreeListener(new TreeListener() {
public void treeCollapsed(TreeEvent event) {
//empty
}
public void treeExpanded(TreeEvent event) {
TreeItem item = (TreeItem) event.item;
if (item.getData(OID_ITEM_FLAG) == null || (item.getData(EXPANDED_ITEM_FLAG) != null)) {
return;
}
if (item.getItemCount() > 0) {
Object obj = item.getItem(0).getData(DUMY_ITEM_FLAG);
if (obj instanceof String && OIDNavigatorDialog.DUMY_ITEM_FLAG.equals((String) obj)) {
item.removeAll();
}
}
searchOID((String) (item.getData(OID_ITEM_FLAG)), item);
item.setData(EXPANDED_ITEM_FLAG, "true");
}
});
setTitle(Messages.titleOIDNavigatorDialog);
setMessage(Messages.msgOIDNavigatorDialog);
return parentComp;
}
Aggregations