use of org.eclipse.swt.widgets.TreeItem in project ACS by ACS-Community.
the class AlarmsView method selectElementFromTree.
public void selectElementFromTree(String ff, String fm, String fc) {
if (ff == null)
return;
if (fm != null && fc != null)
return;
TreeItem[] its = _tree.getItems();
TreeItem sel = null;
for (TreeItem it : its) if (it.getText().compareTo(ff) == 0)
sel = it;
if (fm != null || fc != null) {
String search = null;
if (fm != null) {
its = sel.getItems()[1].getItems();
search = fm;
} else {
its = sel.getItems()[0].getItems();
search = fc;
}
for (TreeItem it : its) if (it.getText().compareTo(search) == 0)
sel = it;
}
_tree.setSelection(sel);
Event e = new Event();
_tree.notifyListeners(SWT.Selection, e);
}
use of org.eclipse.swt.widgets.TreeItem in project ACS by ACS-Community.
the class ReductionsView method sortMultiReductionRuleList.
public void sortMultiReductionRuleList(TreeItem iTree) {
List<ReductionRule> rrList = _reductionManager.getMultiReductionRules();
List<ReductionRule> sortedRRList = new ArrayList<ReductionRule>();
List<String> tmp = new ArrayList<String>();
for (ReductionRule rr : rrList) {
Triplet t = rr.getParent().getTriplet();
String name = "<" + t.getFaultFamily() + "," + t.getFaultMember() + "," + t.getFaultCode() + ">";
tmp.add(name);
}
Collections.sort(tmp, IGNORE_CASE_ORDER);
for (String srr : tmp) for (ReductionRule rr : rrList) {
Triplet t = rr.getParent().getTriplet();
String name = "<" + t.getFaultFamily() + "," + t.getFaultMember() + "," + t.getFaultCode() + ">";
if (name.compareTo(srr) == 0)
sortedRRList.add(rr);
}
rrList = sortedRRList;
for (ReductionRule rule : rrList) {
TreeItem kTree = new TreeItem(iTree, SWT.NONE);
Triplet t = rule.getParent().getTriplet();
kTree.setText("<" + t.getFaultFamily() + "," + t.getFaultMember() + "," + t.getFaultCode() + ">");
kTree.setData(NodeType.MULTIPLICITY_REDUCTION_PARENT_DATA);
}
}
use of org.eclipse.swt.widgets.TreeItem in project cubrid-manager by CUBRID.
the class DatabaseNavigatorMenu method addSelectionListener.
/**
* Add selection listener
*
*/
protected void addSelectionListener() {
MenuItem[] allNodes = getAllMenuNodes();
for (final MenuItem item : allNodes) {
item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (item.getStyle() != SWT.CHECK && item.getStyle() != SWT.RADIO) {
CommonUITool.openErrorBox(parent.getShell(), Messages.plsSelectDb);
return;
}
if (editor.isRunning()) {
CommonUITool.openErrorBox(parent.getShell(), Messages.errEditorRunning);
item.setSelection(false);
return;
}
CubridDatabase oldSelectedDb = (CubridDatabase) getSelectedDb();
final DatabaseMenuItem dbItem = (DatabaseMenuItem) item;
CubridDatabase selectedDb = dbItem.getDatabase();
if (selectedDb != null && selectedDb.getId().equals(IND_DATABASE_ID)) {
if (oldSelectedDb == null) {
return;
}
dbItem.setSelection(false);
// on CM
CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView("com.cubrid.cubridmanager.host.navigator");
if (navigatorView != null) {
TreeViewer treeViewer = navigatorView.getViewer();
Tree tree = treeViewer.getTree();
if (tree == null) {
return;
}
for (int i = 0; i < tree.getItemCount(); i++) {
TreeItem itm = tree.getItem(i);
if (itm == null) {
continue;
}
showDatabaseOnEditingWithHostOnGroup(dbItem, oldSelectedDb, treeViewer, tree, itm);
}
return;
}
// on CQB
navigatorView = CubridNavigatorView.getNavigatorView("com.cubrid.cubridquery.connection.navigator");
if (navigatorView != null) {
TreeViewer treeViewer = navigatorView.getViewer();
Tree tree = treeViewer.getTree();
if (tree == null) {
return;
}
for (int i = 0; i < tree.getItemCount(); i++) {
TreeItem itm = tree.getItem(i);
if (itm == null) {
continue;
}
showDatabaseOnEditingOnGroup(oldSelectedDb, treeViewer, tree, itm);
}
return;
}
return;
} else if (oldSelectedDb != null && selectedDb != null && oldSelectedDb.getId().equals(selectedDb.getId())) {
return;
} else if (selectedDb != null && selectedDb.getId().equals(SELF_DATABASE_ID)) {
if (!NULL_DATABASE_ID.equals(oldSelectedDb.getId())) {
boolean confirm = CommonUITool.openConfirmBox(editor.getSite().getShell(), Messages.changeDbConfirm);
if (!confirm) {
dbItem.setSelection(false);
return;
}
}
if (!handleWithSelfConn(dbItem)) {
return;
}
} else if (oldSelectedDb != null && !oldSelectedDb.getId().equals(NULL_DATABASE_ID)) {
boolean confirm = CommonUITool.openConfirmBox(editor.getSite().getShell(), Messages.changeDbConfirm);
if (!confirm) {
dbItem.setSelection(false);
return;
}
}
boolean valid = editor.resetJDBCConnection();
if (valid) {
selectMenuItem(dbItem);
editor.getCombinedQueryComposite().getMultiDBQueryComp().setMainDatabase(dbItem.getDatabase());
editor.refreshQueryOptions();
} else {
dbItem.setSelection(false);
}
}
// on cm
private void showDatabaseOnEditingWithHost(final CubridDatabase oldSelectedDb, final TreeViewer treeViewer, final Tree tree, final TreeItem itm) {
if (itm != null && itm.getData() != null && itm.getData() instanceof ICubridNode && NodeType.SERVER.equals(((ICubridNode) itm.getData()).getType())) {
String serverName = ((ICubridNode) itm.getData()).getServer().getServerName();
if (serverName == null || oldSelectedDb == null || oldSelectedDb.getServer() == null) {
return;
}
if (!serverName.equals(oldSelectedDb.getServer().getName())) {
return;
}
if (treeViewer != null && !itm.getExpanded()) {
treeViewer.expandToLevel(itm.getData(), 1);
}
Display.getDefault().timerExec(100, new Runnable() {
public void run() {
showDatabaseOnEditingWithHostLoop(oldSelectedDb, tree, itm, 1);
}
});
}
}
// on cqb
private void showDatabaseOnEditing(CubridDatabase oldSelectedDb, TreeViewer treeViewer, Tree tree, TreeItem itm) {
ISchemaNode cNode = (ISchemaNode) itm.getData();
String user = cNode.getDatabase().getUserName();
String dbName = cNode.getDatabase().getDatabaseInfo().getDbName();
String hostName = cNode.getDatabase().getDatabaseInfo().getBrokerIP();
if (user == null || dbName == null || hostName == null) {
return;
}
if (user.equals(oldSelectedDb.getUserName()) && dbName.equals(oldSelectedDb.getDatabaseInfo().getDbName()) && hostName.equals(oldSelectedDb.getDatabaseInfo().getBrokerIP())) {
tree.setSelection(itm);
tree.setTopItem(itm);
final String origDbName = itm.getText();
final TreeItem updatableItem = itm;
itm.setText("[ [ [ " + origDbName + " ] ] ]");
Display.getDefault().timerExec(500, new Runnable() {
public void run() {
updatableItem.setText("[ [ " + origDbName + " ] ]");
}
});
Display.getDefault().timerExec(530, new Runnable() {
public void run() {
updatableItem.setText("[ " + origDbName + " ]");
}
});
Display.getDefault().timerExec(560, new Runnable() {
public void run() {
updatableItem.setText(origDbName);
}
});
}
}
private void showDatabaseOnEditingWithHostLoop(final CubridDatabase oldSelectedDb, final Tree tree, final TreeItem itm, final int count) {
if (count > 10) {
return;
}
boolean ok = false;
try {
for (int j = 0; j < itm.getItemCount(); j++) {
TreeItem sub = itm.getItem(j);
if (sub.getData() instanceof ICubridNode && NodeType.DATABASE_FOLDER.equals(((ICubridNode) sub.getData()).getType())) {
ok = true;
for (int k = 0; k < sub.getItemCount(); k++) {
TreeItem dbNode = sub.getItem(k);
if (dbNode == null || dbNode.getData() == null) {
continue;
}
String dbName = ((ICubridNode) dbNode.getData()).getName();
if (dbName != null && dbName.equals(oldSelectedDb.getName())) {
tree.setSelection(dbNode);
tree.setTopItem(dbNode);
final String origDbName = dbNode.getText();
final TreeItem updatableItem = dbNode;
dbNode.setText("[ [ [ " + origDbName + " ] ] ]");
Display.getDefault().timerExec(500, new Runnable() {
public void run() {
updatableItem.setText("[ [ " + origDbName + " ] ]");
}
});
Display.getDefault().timerExec(530, new Runnable() {
public void run() {
updatableItem.setText("[ " + origDbName + " ]");
}
});
Display.getDefault().timerExec(560, new Runnable() {
public void run() {
updatableItem.setText(origDbName);
}
});
}
}
}
}
} catch (Exception ignored) {
ok = false;
}
if (!ok) {
final int nextCount = count + 1;
Display.getDefault().timerExec(500, new Runnable() {
public void run() {
showDatabaseOnEditingWithHostLoop(oldSelectedDb, tree, itm, nextCount);
}
});
}
}
// on group mode
private void showDatabaseOnEditingWithHostOnGroup(final DatabaseMenuItem dbItem, final CubridDatabase oldSelectedDb, final TreeViewer treeViewer, final Tree tree, final TreeItem item) {
if (item == null || item.getData() == null) {
return;
}
if (item.getData() instanceof CubridGroupNode) {
CubridGroupNode grp = (CubridGroupNode) item.getData();
if (lastSelectedDatabaseMenu == null || lastSelectedDatabaseMenu.getGroupName() == null || grp == null || !lastSelectedDatabaseMenu.getGroupName().equals(grp.getName())) {
return;
}
if (treeViewer != null && !item.getExpanded()) {
treeViewer.expandToLevel(item.getData(), 1);
Display.getDefault().timerExec(500, new Runnable() {
public void run() {
for (int i = 0; i < item.getItemCount(); i++) {
final TreeItem itm = item.getItem(i);
if (itm == null) {
continue;
}
showDatabaseOnEditingWithHost(oldSelectedDb, treeViewer, tree, itm);
}
}
});
} else {
for (int i = 0; i < item.getItemCount(); i++) {
final TreeItem itm = item.getItem(i);
if (itm == null) {
continue;
}
showDatabaseOnEditingWithHost(oldSelectedDb, treeViewer, tree, itm);
}
}
} else {
showDatabaseOnEditingWithHost(oldSelectedDb, treeViewer, tree, item);
}
}
// on group mode
private void showDatabaseOnEditingOnGroup(final CubridDatabase oldSelectedDb, final TreeViewer treeViewer, final Tree tree, final TreeItem item) {
if (item == null || item.getData() == null) {
return;
}
if (item.getData() instanceof CubridGroupNode) {
CubridGroupNode grp = (CubridGroupNode) item.getData();
if (lastSelectedDatabaseMenu == null || lastSelectedDatabaseMenu.getGroupName() == null || grp == null || !lastSelectedDatabaseMenu.getGroupName().equals(grp.getName())) {
return;
}
if (treeViewer != null && !item.getExpanded()) {
treeViewer.expandToLevel(item.getData(), 1);
Display.getDefault().timerExec(500, new Runnable() {
public void run() {
for (int i = 0; i < item.getItemCount(); i++) {
final TreeItem itm = item.getItem(i);
if (itm == null) {
continue;
}
showDatabaseOnEditing(oldSelectedDb, treeViewer, tree, itm);
}
}
});
} else {
for (int i = 0; i < item.getItemCount(); i++) {
final TreeItem itm = item.getItem(i);
if (itm == null) {
continue;
}
showDatabaseOnEditing(oldSelectedDb, treeViewer, tree, itm);
}
}
} else {
showDatabaseOnEditing(oldSelectedDb, treeViewer, tree, item);
}
}
});
}
// multiSelectItem.addSelectionListener(new SelectionAdapter() {
//
// public void widgetSelected(SelectionEvent e) {
// DatabaseSelectionDialog dialog = new DatabaseSelectionDialog(multiSelectItem.getParent().getShell());
// dialog.setItems(dbSelectionMenu.getItems());
// dialog.open();
// CubridDatabase[] databases = dialog.getSelectedDbItem();
// if (databases.length == 0) {
// return;
// }
// Map<CubridDatabase, DatabaseMenuItem> allItems = new HashMap<CubridDatabase, DatabaseMenuItem>();
// for (MenuItem item : dbSelectionMenu.getItems()) {
// if (item instanceof DatabaseMenuItem) {
// DatabaseMenuItem dbItem = (DatabaseMenuItem)item;
// dbItem.setSelection(false);
// allItems.put(dbItem.getDatabase(), dbItem);
// }
// }
// List<DatabaseMenuItem> selected = new ArrayList<DatabaseMenuItem>();
// for (CubridDatabase db : databases) {
// if (!allItems.containsKey(db)) {
// continue;
// }
// allItems.get(db).setSelection(true);
// selected.add(allItems.get(db));
// }
// selectMenuItem(selected.toArray(new DatabaseMenuItem[0]));
// }
// });
}
use of org.eclipse.swt.widgets.TreeItem in project cubrid-manager by CUBRID.
the class DatabaseSelectionDialog method checkItemChild.
private void checkItemChild(TreeItem item, boolean select) {
if (item.getItems() == null || item.getItemCount() == 0)
return;
else {
for (TreeItem cItem : item.getItems()) {
cItem.setChecked(select);
checkItemChild(cItem, select);
}
}
}
use of org.eclipse.swt.widgets.TreeItem in project cubrid-manager by CUBRID.
the class DatabaseSelectionDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite parentComp = (Composite) super.createDialogArea(parent);
Composite newComp = new Composite(parentComp, SWT.NONE);
GridLayout dialogShellLayout = new GridLayout();
dialogShellLayout.makeColumnsEqualWidth = true;
newComp.setLayout(dialogShellLayout);
GridData compData = new GridData();
compData.grabExcessHorizontalSpace = true;
compData.grabExcessVerticalSpace = true;
compData.verticalAlignment = GridData.FILL;
compData.horizontalAlignment = GridData.FILL;
newComp.setLayoutData(compData);
try {
{
GridData dbTreeLData = new GridData();
dbTreeLData.grabExcessHorizontalSpace = true;
dbTreeLData.grabExcessVerticalSpace = true;
dbTreeLData.verticalAlignment = GridData.FILL;
dbTreeLData.horizontalAlignment = GridData.FILL;
dbTree = new Tree(newComp, SWT.BORDER | SWT.LINE_SOLID | SWT.MULTI | SWT.CHECK | SWT.H_SCROLL | SWT.V_SCROLL);
dbTree.setLayoutData(dbTreeLData);
}
{
buttonComp = new Composite(newComp, SWT.NONE);
RowLayout buttonCompLayout = new RowLayout(org.eclipse.swt.SWT.HORIZONTAL);
GridData buttonCompLData = new GridData();
buttonComp.setLayoutData(buttonCompLData);
buttonComp.setLayout(buttonCompLayout);
{
btnSelectAll = new Button(buttonComp, SWT.PUSH | SWT.CENTER);
RowData btnSelectAllLData = new RowData();
btnSelectAll.setLayoutData(btnSelectAllLData);
btnSelectAll.setText(Messages.lblSelectAll);
btnSelectAll.addSelectionListener(this);
btnSelectAll.setData(KEY_ID, TYPE.SELECT);
btnSelectAll.setData(KEY_VALUE, true);
btnSelectAll.setVisible(false);
}
{
btnUnSelectAll = new Button(buttonComp, SWT.PUSH | SWT.CENTER);
RowData btnUnSelectAllLData = new RowData();
btnUnSelectAll.setLayoutData(btnUnSelectAllLData);
btnUnSelectAll.setText(Messages.lblDeSelectAll);
// btnUnSelectAll.setImage(CommonUIPlugin.getImage("icons/unchecked.gif"));
btnUnSelectAll.addSelectionListener(this);
btnUnSelectAll.setData(KEY_ID, TYPE.SELECT);
btnUnSelectAll.setData(KEY_VALUE, false);
btnUnSelectAll.setVisible(false);
}
{
btnExpandAll = new Button(buttonComp, SWT.PUSH | SWT.CENTER);
RowData btnExpandAllLData = new RowData();
btnExpandAll.setLayoutData(btnExpandAllLData);
btnExpandAll.setText(Messages.lblExpandAll);
btnExpandAll.addSelectionListener(this);
btnExpandAll.setData(KEY_ID, TYPE.EXPAND);
btnExpandAll.setData(KEY_VALUE, true);
btnExpandAll.setVisible(false);
}
{
btnUnExpandAll = new Button(buttonComp, SWT.PUSH | SWT.CENTER);
RowData btnUnExpandAllLData = new RowData();
btnUnExpandAll.setLayoutData(btnUnExpandAllLData);
btnUnExpandAll.setText(Messages.lblUnExpandAll);
// btnUnExpandAll.setImage(CommonUIPlugin.getImage("icons/action/collapseall.gif"));
btnUnExpandAll.addSelectionListener(this);
btnUnExpandAll.setData(KEY_ID, TYPE.EXPAND);
btnUnExpandAll.setData(KEY_VALUE, false);
btnUnExpandAll.setVisible(false);
}
}
} catch (Exception e) {
e.printStackTrace();
}
dbTree.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
TreeItem item = (TreeItem) e.item;
boolean checked = item.getChecked();
checkItems(item.getItems(), checked);
if (item.getParentItem() != null) {
if (checked)
item.getParentItem().setChecked(checked);
checkParentChecked(item.getParentItem(), checked);
}
}
private void checkItems(TreeItem[] items, boolean value) {
if (items == null || items.length == 0)
return;
for (TreeItem item : items) {
item.setChecked(value);
}
}
private void checkParentChecked(TreeItem pitem, boolean value) {
TreeItem[] items = pitem.getItems();
for (TreeItem item : items) {
if (item.getChecked() == value) {
continue;
} else {
return;
}
}
pitem.setChecked(value);
}
});
initTreeData();
if (this.lastSelectedDbs != null)
initSelection(this.lastSelectedDbs);
return parentComp;
}
Aggregations