use of org.eclipse.ui.dialogs.ContainerCheckedTreeViewer in project cubrid-manager by CUBRID.
the class MultiDBQueryComposite method initialize.
/**
* Create the SQL history composite
*/
public void initialize() {
Composite toolBarComposite = new Composite(this, SWT.NONE);
GridLayout gridLayout = new GridLayout(2, false);
gridLayout.verticalSpacing = 0;
gridLayout.horizontalSpacing = 10;
gridLayout.marginWidth = 0;
gridLayout.marginHeight = 0;
toolBarComposite.setLayout(gridLayout);
toolBarComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
ToolBar toolBar = new ToolBar(toolBarComposite, SWT.FLAT | SWT.RIGHT);
toolBar.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));
ToolItem refreshToolItem = new ToolItem(toolBar, SWT.PUSH);
refreshToolItem.setText(Messages.lblItemRefreshMulti);
refreshToolItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_refresh.png"));
refreshToolItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/query_refresh.png"));
refreshToolItem.setToolTipText(Messages.refresh);
refreshToolItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
//refresh may set tree to group type or not
//so mark the select db then set it to checked after set input
// Object[] checkedObject = ctv.getCheckedElements();
setInput();
// for (Object o : checkedObject) {
// if (o instanceof CubridDatabase) {
// ctv.setChecked(o, true);
// }
// }
// refresh(editor.getSelectedDatabase());
}
});
runItem = new ToolItem(toolBar, SWT.PUSH);
runItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_run.png"));
runItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/query_run_disabled.png"));
runItem.setText(Messages.lblItemRunMulti);
runItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
editor.runMultiQuery();
}
});
Label lblNotice = new Label(toolBarComposite, SWT.None);
lblNotice.setText(Messages.qedit_multiDBQueryComp_noticeToolbarMsg);
lblNotice.setLayoutData(new GridData(SWT.TRAIL, SWT.CENTER, true, false));
// create the query result tab folder
multiDBQueryCompTabFolder = new CTabFolder(this, SWT.BOTTOM);
multiDBQueryCompTabFolder.setSimple(false);
multiDBQueryCompTabFolder.setUnselectedImageVisible(true);
multiDBQueryCompTabFolder.setUnselectedCloseVisible(true);
multiDBQueryCompTabFolder.setSelectionBackground(CombinedQueryEditorComposite.BACK_COLOR);
multiDBQueryCompTabFolder.setSelectionForeground(ResourceManager.getColor(SWT.COLOR_BLACK));
multiDBQueryCompTabFolder.setLayout(new GridLayout(1, true));
multiDBQueryCompTabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
//TabContextMenuManager tabContextMenuManager = new TabContextMenuManager(multiDBQueryCompTabFolder);
//tabContextMenuManager.createContextMenu();
multiDBQueryCompTabItem = new CTabItem(resultTabFolder, SWT.NONE);
multiDBQueryCompTabItem.setText(Messages.qedit_multiDBQueryComp_folder);
multiDBQueryCompTabItem.setControl(this);
multiDBQueryCompTabItem.setShowClose(false);
SashForm bottomSash = new SashForm(multiDBQueryCompTabFolder, SWT.VERTICAL);
bottomSash.SASH_WIDTH = SASH_WIDTH;
bottomSash.setBackground(CombinedQueryEditorComposite.BACK_COLOR);
SashForm tailSash = new SashForm(bottomSash, SWT.HORIZONTAL);
tailSash.SASH_WIDTH = SASH_WIDTH;
tailSash.setBackground(CombinedQueryEditorComposite.BACK_COLOR);
Composite treeComp = new Composite(tailSash, SWT.NONE);
{
treeComp.setLayoutData(new GridData(GridData.FILL_BOTH));
treeComp.setLayout(new GridLayout());
}
ctv = new ContainerCheckedTreeViewer(treeComp, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
ctv.getControl().setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, -1, 200));
ctv.setContentProvider(new MultiDBQueryTreeContentProvider());
ctv.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
if (lastSelectedTime != 0 && lastSelectedTime > System.currentTimeMillis()) {
ctv.setChecked(event.getElement(), true);
return;
}
ctv.setChecked(event.getElement(), false);
lastSelectedTime = System.currentTimeMillis() + 100;
if (getQueryDatabaseList().size() > 0 && editor.getAllQueries().trim().length() != 0) {
editor.setMultiQueryRunItemStatus(true);
} else if (getQueryDatabaseList().size() == 0) {
editor.setMultiQueryRunItemStatus(false);
}
//if (!event.getChecked()) {
selectedNodes.remove(event.getElement());
if (event.getElement() instanceof CubridDatabase) {
CubridDatabase database = (CubridDatabase) event.getElement();
if (database.getRunningType() == DbRunningType.STANDALONE || !database.isLogined()) {
//ctv.setChecked(event.getElement(), false);
selectedNodes.remove(database);
} else {
if (database.getData(INDEXKEY) == null) {
database.setData(INDEXKEY, String.valueOf(databaseIndex++));
}
}
} else if (event.getElement() instanceof CubridServer) {
CubridServer serverNode = (CubridServer) event.getElement();
for (ICubridNode dbFolderNode : serverNode.getChildren()) {
for (ICubridNode dbNode : dbFolderNode.getChildren()) {
if (dbNode instanceof CubridDatabase) {
CubridDatabase database = (CubridDatabase) dbNode;
if (database.getRunningType() == DbRunningType.STANDALONE || !database.isLogined()) {
//ctv.setChecked(dbNode, false);
selectedNodes.remove(database);
} else if (ctv.getChecked(dbNode)) {
ctv.setChecked(dbNode, true);
if (dbNode.getData(INDEXKEY) == null) {
dbNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
}
} else {
ctv.setChecked(dbNode, true);
}
}
}
//only has one db folder so first time break it
break;
}
} else if (event.getElement() instanceof ICubridNode) {
ICubridNode node = (ICubridNode) event.getElement();
if (node.getType().equals(NodeType.DATABASE_FOLDER)) {
for (ICubridNode dbNode : node.getChildren()) {
if (dbNode instanceof CubridDatabase) {
CubridDatabase database = (CubridDatabase) dbNode;
if (database.getRunningType() == DbRunningType.STANDALONE || !database.isLogined()) {
ctv.setChecked(dbNode, false);
} else if (ctv.getChecked(dbNode)) {
ctv.setChecked(dbNode, true);
if (dbNode.getData(INDEXKEY) == null) {
dbNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
}
} else {
ctv.setChecked(dbNode, false);
}
}
}
}
// else if (node.getType().equals(NodeType.GROUP)) {
// for (ICubridNode childNode : node.getChildren()) {
// //CQB tree
// if(childNode instanceof CubridDatabase) {
// CubridDatabase database = (CubridDatabase) childNode;
// if (database.getRunningType() == DbRunningType.STANDALONE
// || !database.isLogined()) {
// if (childNode.getData(INDEXKEY) == null) {
// childNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
// }
// }
// continue;
// }
// //CM tree
// for (ICubridNode dbFolderNode : childNode.getChildren()) {
// for (ICubridNode dbNode : dbFolderNode.getChildren()) {
// if(dbNode instanceof CubridDatabase) {
// CubridDatabase database = (CubridDatabase) dbNode;
// if (database.getRunningType() == DbRunningType.STANDALONE
// || !database.isLogined()) {
// ctv.setChecked(dbNode, false);
// } else if (ctv.getChecked(dbNode)) {
// ctv.setChecked(dbNode, true);
// if (dbNode.getData(INDEXKEY) == null) {
// dbNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
// }
// } else {
// ctv.setChecked(dbNode, false);
// }
// }
// }
// }
// //only has one db folder so first time break it
// break;
// }
// }
}
ctv.refresh();
}
});
ctv.getTree().addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent event) {
//mac can't drag and drop,so support copy and paste db node
if (((event.stateMask & SWT.CTRL) != 0) || ((event.stateMask & SWT.COMMAND) != 0) && event.keyCode == 'v') {
final Clipboard cb = new Clipboard(getShell().getDisplay());
String plainText = (String) cb.getContents(TextTransfer.getInstance());
String[] databaseNameArray = plainText.split(",");
selectedNodes.addAll(getDatabaseNode(databaseNameArray));
setInput();
}
}
});
// ctv.addDoubleClickListener(LayoutManager.getInstance());
// ctv.addTreeListener(new ITreeViewerListener() {
// public void treeCollapsed(TreeExpansionEvent event) {
// CommonTool.clearExpandedElements(ctv);
// }
//
// public void treeExpanded(TreeExpansionEvent event) {
// CommonTool.clearExpandedElements(ctv);
// }
// });
final Tree tableTree = ctv.getTree();
tableTree.setHeaderVisible(true);
tableTree.setLinesVisible(true);
final TreeViewerColumn dbCol = new TreeViewerColumn(ctv, SWT.NONE);
dbCol.setLabelProvider(new MultiDBQueryTreeColumnLabelProvider());
dbCol.getColumn().setWidth(250);
dbCol.getColumn().setText(Messages.qedit_multiDBQueryComp_tree_dbCol);
final TreeViewerColumn indexCol = new TreeViewerColumn(ctv, SWT.NONE);
indexCol.setLabelProvider(new MultiDBQueryTreeColumnLabelProvider());
indexCol.getColumn().setWidth(50);
indexCol.getColumn().setText(Messages.qedit_multiDBQueryComp_tree_indexCol);
indexCol.setEditingSupport(new EditingSupport(ctv) {
TextCellEditor textCellEditor;
protected boolean canEdit(Object element) {
if (element instanceof ICubridNode) {
ICubridNode node = (ICubridNode) element;
if (node.getType() == NodeType.DATABASE) {
CubridDatabase database = (CubridDatabase) element;
if ((database.getRunningType() == DbRunningType.CS && database.isLogined())) {
return true;
}
}
}
return false;
}
protected CellEditor getCellEditor(Object element) {
if (textCellEditor == null) {
textCellEditor = new TextCellEditor(ctv.getTree());
textCellEditor.setValidator(new IndexCellEditorValidator());
textCellEditor.addListener(new ICellEditorListener() {
public void applyEditorValue() {
}
public void cancelEditor() {
}
public void editorValueChanged(boolean oldValidState, boolean newValidState) {
}
});
}
return textCellEditor;
}
protected Object getValue(Object element) {
final ICubridNode node = (ICubridNode) element;
String index = (String) node.getData(INDEXKEY);
if (index == null) {
return "";
} else {
return index;
}
}
protected void setValue(Object element, Object value) {
if (value == null) {
return;
}
try {
Integer.valueOf((String) value);
} catch (Exception e) {
return;
}
final ICubridNode node = (ICubridNode) element;
node.setData(INDEXKEY, value);
// setAllParentExpandOrCollapse(node.getParent(), true);
ctv.refresh();
}
/**
* MyCellEditorValidator
*
* @author fulei
*
*/
class IndexCellEditorValidator implements ICellEditorValidator {
/**
* isValid
*
* @param value Object
* @return String
*/
public String isValid(Object value) {
try {
Integer.valueOf((String) value);
} catch (Exception e) {
CommonUITool.openErrorBox(Messages.qedit_multiDBQueryComp_tree_indexErr);
return Messages.qedit_multiDBQueryComp_tree_indexErr;
}
return null;
}
}
});
final TreeViewerColumn commentCol = new TreeViewerColumn(ctv, SWT.NONE);
commentCol.setLabelProvider(new MultiDBQueryTreeColumnLabelProvider());
commentCol.getColumn().setWidth(200);
commentCol.getColumn().setText(Messages.qedit_multiDBQueryComp_tree_commentCol);
CTabItem tabItem = new CTabItem(multiDBQueryCompTabFolder, SWT.NONE);
tabItem.setText(Messages.qedit_multiDBQueryComp_tabItem);
tabItem.setControl(bottomSash);
tabItem.setShowClose(false);
setInput();
// HostNodePersistManager.getInstance().getAllServer();
multiDBQueryCompTabFolder.setSelection(tabItem);
dragController = new MultiDBQueryDNDController(this, ctv);
dragController.registerDropTarget();
}
use of org.eclipse.ui.dialogs.ContainerCheckedTreeViewer in project tdi-studio-se by Talend.
the class SelectDeleteProjectDialog method createTreeViewer.
private void createTreeViewer(Composite parent) {
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginWidth = 0;
layout.makeColumnsEqualWidth = false;
parent.setLayout(layout);
parent.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH));
GridData listData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
treeViewer = new ContainerCheckedTreeViewer(parent);
treeViewer.getControl().setLayoutData(listData);
// treeViewer.setContentProvider(getResourceProvider(IResource.FOLDER | IResource.PROJECT));
treeViewer.setContentProvider(getResourceProvider(IResource.PROJECT));
// treeViewer.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider());
treeViewer.setLabelProvider(new LabelProvider() {
@Override
public final String getText(Object element) {
// query the element for its label
//$NON-NLS-1$
String label = "";
if (element instanceof IProject) {
IProject project = (IProject) element;
label = getLabel(project.getName());
} else if (element instanceof IFolder) {
IFolder folder = (IFolder) element;
label = getLabel(folder.getName());
}
return label;
}
private String getLabel(String name) {
List<Project> proItem = getProjectItem();
for (int i = 0; i < proItem.size(); i++) {
Project p = proItem.get(i);
String proName = p.getTechnicalLabel();
if (proName.equals(name)) {
return ProjectManager.getProjectDisplayLabel(p.getEmfProject());
}
}
return name;
}
@Override
public final Image getImage(Object element) {
if (element instanceof IProject) {
return ImageProvider.getImage(ERepositoryImages.PROJECT_ICON);
} else if (element instanceof IFolder) {
return ImageProvider.getImage(ERepositoryImages.FOLDER_ICON);
}
return null;
}
});
treeViewer.setInput(projectItemList);
treeViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
addTreeListener();
createButtons(parent);
}
Aggregations