use of org.eclipse.swt.events.TreeEvent in project mdw-designer by CenturyLinkCloud.
the class ProcessExplorerView method createPartControl.
@Override
public void createPartControl(Composite parent) {
treeViewer = new TreeViewer(parent) {
protected void handleTreeExpand(TreeEvent event) {
if (event.item.getData() instanceof WorkflowProject) {
final WorkflowProject project = (WorkflowProject) event.item.getData();
if (project.isFilePersist() && !project.isRemote()) {
// authentication not needed
project.setUser(new User(System.getProperty("user.name")));
} else {
// user authentication
Boolean authenticated = project.isAuthenticated();
if (authenticated == null) {
// has to be in a separate
// thread to take effect
event.item.getDisplay().asyncExec(new Runnable() {
public void run() {
treeViewer.collapseToLevel(project, TreeViewer.ALL_LEVELS);
}
});
return;
}
if (!authenticated) {
LoginDialog loginDialog = new LoginDialog(MdwPlugin.getShell(), project);
int res = loginDialog.open();
if (res == Dialog.CANCEL || !project.isAuthenticated()) {
// has
// to
// be
// in
// a
// separate
// thread
// to
// take
// effect
event.item.getDisplay().asyncExec(new Runnable() {
public void run() {
treeViewer.collapseToLevel(project, TreeViewer.ALL_LEVELS);
}
});
return;
}
}
super.handleTreeExpand(event);
return;
}
}
super.handleTreeExpand(event);
}
};
ProcessExplorerContentProvider contentProvider = new ProcessExplorerContentProvider();
// for
WorkflowProjectManager.getInstance().addElementChangeListener(contentProvider);
// project
// adds/deletes
treeViewer.setContentProvider(contentProvider);
treeViewer.setLabelProvider(new ProcessExplorerLabelProvider());
treeViewer.setInput(WorkflowProjectManager.getInstance().getWorkflowProjects());
treeViewer.collapseAll();
clipboard = new Clipboard(parent.getDisplay());
// action group
actionGroup = new ProcessExplorerActionGroup(this);
actionGroup.fillActionBars(getViewSite().getActionBars());
// context menu
MenuManager menuMgr = new MdwMenuManager("Process Explorer");
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(this);
contextMenu = menuMgr.createContextMenu(treeViewer.getTree());
treeViewer.getTree().setMenu(contextMenu);
getSite().registerContextMenu(menuMgr, treeViewer);
treeViewer.addOpenListener(new IOpenListener() {
public void open(OpenEvent event) {
for (Object item : getSelection().toList()) {
if (!actionGroup.getActionHandler().open((WorkflowElement) item))
expand(item);
}
}
});
treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
handleSelectionChanged((IStructuredSelection) event.getSelection());
}
});
// drag and drop support
Transfer[] transfers = new Transfer[] { TextTransfer.getInstance() };
dragSource = new ProcessExplorerDragSource(treeViewer);
treeViewer.addDragSupport(DND.DROP_MOVE | DND.DROP_COPY, transfers, dragSource);
dropTarget = new ProcessExplorerDropTarget(treeViewer);
treeViewer.addDropSupport(DND.DROP_MOVE | DND.DROP_COPY, transfers, dropTarget);
contextListener = new ProcessExplorerContextListener();
getSite().getPage().addPartListener(contextListener);
MdwPlugin.getPluginWorkbench().getHelpSystem().setHelp(parent, MdwPlugin.getPluginId() + ".process_explorer_help");
}
use of org.eclipse.swt.events.TreeEvent in project janrufmonitor by tbrandt77.
the class AbstractTreeTableApplication method createContents.
protected Control createContents(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(1, false));
List actions = this.getMenuBuilder().getToolbarActions();
if (this.isShowToolbar() && actions != null && actions.size() > 0 && this.getToolBarManager() != null) {
ToolBar tb = this.getToolBarManager().createControl(composite);
for (int i = 0, j = actions.size(); i < j; i++) {
final org.eclipse.jface.action.IAction a = (org.eclipse.jface.action.IAction) actions.get(i);
if (a != null && a.getImageDescriptor() != null) {
ToolItem ti = new ToolItem(tb, SWT.PUSH);
Image img = (a).getImageDescriptor().createImage();
ti.setImage(img);
ti.setText(a.getText());
if (a instanceof AbstractAction) {
ti.setText(((AbstractAction) a).getShortText());
}
ti.setToolTipText(a.getToolTipText());
ti.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
a.run();
}
});
}
}
}
addRenderBeforeTableHooks(composite);
// add filter capability
Composite line = new Composite(composite, SWT.NONE);
line.setLayout(new GridLayout(6, false));
if (this.getFilterManager() != null) {
Composite view = new Composite(line, SWT.NONE);
view.setLayout(new GridLayout(2, false));
new Label(view, SWT.NONE).setText(this.getI18nManager().getString(this.getNamespace(), "current_view", "label", this.getLanguage()));
new Label(view, SWT.NONE);
this.currentView = new Combo(view, SWT.READ_ONLY | SWT.FLAT);
this.currentView.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
String filterName = currentView.getItem(currentView.getSelectionIndex());
IFilter[] selectedFilters = (IFilter[]) currentView.getData(filterName);
getApplication().getConfiguration().setProperty(CFG_FILTER, getFilterManager().getFiltersToString(selectedFilters));
getApplication().storeConfiguration();
updateViews(true);
}
});
if (getFilterAction() != null) {
Button filterAction = new Button(view, SWT.PUSH);
filterAction.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
de.janrufmonitor.ui.jface.application.action.IAction action = getFilterAction();
if (action != null)
action.run();
}
});
filterAction.setImage(SWTImageManager.getInstance(this.getRuntime()).get(IJAMConst.IMAGE_KEY_FILTER_GIF));
filterAction.pack();
}
}
final de.janrufmonitor.ui.jface.application.action.IAction action = getQuickSearchAction();
if (this.isShowQuickSearch() && action != null) {
Composite view = new Composite(line, SWT.NONE);
view.setLayout(new GridLayout(2, false));
new Label(view, SWT.NONE).setText(this.getI18nManager().getString(this.getNamespace(), "quicksearch", "label", this.getLanguage()));
new Label(view, SWT.NONE);
final Combo search = new Combo(view, SWT.FLAT);
final String empty = this.getConfiguration().getProperty(CFG_SEARCHTERMS, "");
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.minimumWidth = 300;
search.setLayoutData(gd);
search.add(empty);
final List sh = this.getSearchHistory();
for (int i = 0; i < sh.size(); i++) {
if (!empty.equalsIgnoreCase((String) sh.get(i)))
search.add((String) sh.get(i));
}
search.select(0);
search.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
action.setData(search.getText());
action.run();
}
});
search.setToolTipText(this.getI18nManager().getString(this.getNamespace(), "quicksearch", "description", this.getLanguage()));
search.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.character == 13) {
action.setData(search.getText());
if (!sh.contains(search.getText())) {
sh.add(search.getText());
search.add(search.getText());
}
setSearchHistory(sh);
action.run();
}
}
});
}
Tree t = new Tree(composite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI);
viewer = new TreeViewer(t);
Tree tree = ((TreeViewer) viewer).getTree();
tree.setLayoutData(new GridData(GridData.FILL_BOTH));
tree.setHeaderVisible(true);
tree.addTreeListener(new TreeAdapter() {
public void treeExpanded(TreeEvent e) {
if (e.item != null) {
TreeItem item = (TreeItem) e.item;
TreeItem[] items = item.getItems();
for (int i = 0; i < items.length; i++) {
items[i].setBackground(item.getBackground());
items[i].setForeground(item.getForeground());
}
}
}
});
this.updateProviders();
// added drag and drop feature
if (this.getDropTargetHandler() != null) {
int operations = DND.DROP_MOVE;
Transfer[] types = new Transfer[] { FileTransfer.getInstance() };
DropTarget target = new DropTarget(tree, operations);
target.setTransfer(types);
target.addDropListener(new DropTargetAdapter() {
public void drop(DropTargetEvent event) {
// A drop has occurred, copy over the data
if (event.data == null) {
event.detail = DND.DROP_NONE;
return;
}
getDropTargetHandler().execute((String[]) event.data);
}
});
}
FontData tableFontData = tree.getFont().getFontData()[0];
int size = Integer.parseInt(this.getConfiguration().getProperty(CFG_FONT_SIZE, "8"));
tree.setFont(this.getSizedFont(tableFontData, size, false));
AbstractMenuBuilder mb = this.getMenuBuilder();
if (mb != null)
tree.setMenu(mb.createPopupMenu(tree));
tree.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.character == SWT.DEL) {
de.janrufmonitor.ui.jface.application.action.IAction action = getDeleteAction();
if (action != null)
action.run();
}
}
});
tree.addMouseListener(new MouseAdapter() {
public void mouseDoubleClick(MouseEvent e) {
de.janrufmonitor.ui.jface.application.action.IAction action = getAssignAction();
if (action != null)
action.run();
}
});
// 2006/08/02: this is a workaround: No multiple line in table possibe
Listener paintListener = new Listener() {
int name_column = getColumnNumber("name");
int address_column = getColumnNumber("address");
public void handleEvent(Event event) {
if (event.index != name_column && event.index != address_column)
return;
switch(event.type) {
case SWT.MeasureItem:
{
TreeItem item = (TreeItem) event.item;
String text = item.getText(event.index);
Point size = event.gc.textExtent(text);
event.width = size.x;
event.height = Math.max(event.height, size.y + 7);
break;
}
case SWT.PaintItem:
{
TreeItem item = (TreeItem) event.item;
String text = item.getText(event.index);
Point size = event.gc.textExtent(text);
int offset2 = (event.index == 0 ? Math.max(0, (event.height - size.y) / 2) : 0) + 3;
event.gc.drawText(text, event.x + offset2, event.y + offset2, true);
break;
}
case SWT.EraseItem:
{
event.detail &= ~SWT.FOREGROUND;
TreeItem item = (TreeItem) event.item;
event.gc.setBackground(item.getBackground(event.index));
event.gc.setForeground(item.getForeground(event.index));
break;
}
}
}
};
tree.addListener(SWT.MeasureItem, paintListener);
tree.addListener(SWT.PaintItem, paintListener);
tree.addListener(SWT.EraseItem, paintListener);
addRenderAfterTableHooks(composite);
tree.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (e.widget instanceof Tree) {
TreeItem[] selectedItems = ((Tree) e.widget).getSelection();
if (selectedItems != null && selectedItems.length > 0)
lastMarkedTreeItem = ((Tree) e.widget).indexOf(selectedItems[0]);
else
lastMarkedTreeItem = -1;
}
}
});
updateViews(true);
List startupActions = this.getMenuBuilder().getStartupActions();
if (startupActions != null && startupActions.size() > 0) {
IAction a = null;
for (int i = 0, j = startupActions.size(); i < j; i++) {
a = (IAction) startupActions.get(i);
if (a != null) {
a.setApplication(this);
a.run();
}
}
}
return composite;
}
use of org.eclipse.swt.events.TreeEvent in project tdq-studio-se by Talend.
the class DQRespositoryView method createPartControl.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.navigator.CommonNavigator#createPartControl(org.eclipse .swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
parent.setLayout(new BorderLayout());
Composite topComp = new Composite(parent, SWT.NONE);
topComp.setFont(parent.getFont());
topComp.setLayoutData(BorderLayout.NORTH);
Composite bottomComp = new Composite(parent, SWT.NONE);
bottomComp.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
bottomComp.setFont(parent.getFont());
bottomComp.setLayoutData(BorderLayout.CENTER);
topComp.setLayout(new BorderLayout());
FillLayout bottomLayout = new FillLayout(SWT.VERTICAL);
bottomComp.setLayout(bottomLayout);
createTreeFilter(topComp);
super.createPartControl(bottomComp);
// For removing the popup menu of DQRepositoryView.
// $NON-NLS-1$
MenuManager menuMgr = new MenuManager("org.talend.dataprofiler.core.ui.views.DQRespositoryView");
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager menuManager) {
ISelection selection = getCommonViewer().getSelection();
getNavigatorActionService().setContext(new ActionContext(selection));
getNavigatorActionService().fillContextMenu(menuManager);
}
});
Menu menu = menuMgr.createContextMenu(getCommonViewer().getTree());
getCommonViewer().getTree().setMenu(menu);
this.addViewerFilter(EMFObjFilter.FILTER_ID);
this.addViewerFilter(ReportingFilter.FILTER_ID);
this.addViewerFilter(FolderObjFilter.FILTER_ID);
adjustFilter();
activateContext();
getCommonViewer().setSorter(null);
getCommonViewer().getTree().addTreeListener(new TreeAdapter() {
@Override
public void treeExpanded(TreeEvent e) {
TreeItem item = (TreeItem) e.item;
if (!item.getText().endsWith(")")) {
// $NON-NLS-1$
Object obj = item.getData();
if (obj instanceof TableFolderNode || obj instanceof ViewFolderNode || obj instanceof ColumnFolderNode) {
// $NON-NLS-1$ //$NON-NLS-2$
item.setText(item.getText() + "(" + item.getItemCount() + ")");
}
}
super.treeExpanded(e);
}
});
getCommonViewer().getTree().addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
boolean superDoubleClick = true;
Tree tree = (Tree) e.getSource();
Point point = new Point(e.x, e.y);
final TreeItem item = tree.getItem(point);
if (item != null) {
Object obj = item.getData();
if (obj instanceof AbstractFolderNode) {
AbstractFolderNode node = (AbstractFolderNode) obj;
node.loadChildren();
Object[] children = node.getChildren();
if (children != null) {
if (item.getText().indexOf("(") > 0) {
// $NON-NLS-1$
item.setText(// $NON-NLS-1$ //$NON-NLS-2$
item.getText().substring(0, item.getText().indexOf("(")) + "(" + children.length + // $NON-NLS-1$
")");
} else {
// $NON-NLS-1$ //$NON-NLS-2$
item.setText(item.getText() + "(" + children.length + ")");
}
}
}
if (obj instanceof IndicatorDefinition) {
IndicatorDefinition indicatorDefinition = (IndicatorDefinition) obj;
// reload object
indicatorDefinition = DefinitionHandler.getInstance().getIndicatorDefinition(indicatorDefinition.getLabel());
IndicatorEditorInput input = new IndicatorEditorInput(indicatorDefinition);
try {
CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, IndicatorEditor.class.getName());
} catch (PartInitException e1) {
log.error(e1, e1);
}
}
if (obj instanceof DQRepositoryNode) {
if (obj instanceof ReportFileRepNode) {
new OpenItemEditorAction(new IRepositoryNode[] { (IRepositoryNode) obj }).run();
} else if (obj instanceof DFConnectionRepNode) {
new EditFileDelimitedAction((IRepositoryNode) obj).run();
} else if (obj instanceof HadoopClusterConnectionRepNode && HadoopClusterUtils.getDefault().isServiceInstalled()) {
new EditHadoopClusterAction((IRepositoryNode) obj).run();
} else if (obj instanceof HDFSOfHCConnectionNode && HadoopClusterUtils.getDefault().isServiceInstalled()) {
new EditHDFSConnectionAction((IRepositoryNode) obj).run();
} else if (obj instanceof DFTableRepNode) {
new EditDFTableAction((IRepositoryNode) obj).run();
} else if (obj instanceof ContextRepNode) {
new DQEditContextAction((ContextRepNode) obj, false).run();
} else {
DQRepositoryNode repoNode = (DQRepositoryNode) obj;
if (RepositoryNodeHelper.canOpenEditor(repoNode)) {
OpenItemEditorAction openItemEditorAction = new OpenItemEditorAction(new IRepositoryNode[] { repoNode });
openItemEditorAction.run();
}
if (repoNode instanceof AnalysisRepNode || repoNode instanceof ReportRepNode || repoNode instanceof SysIndicatorDefinitionRepNode || repoNode instanceof PatternRepNode || repoNode instanceof RuleRepNode) {
superDoubleClick = false;
}
}
}
}
if (superDoubleClick) {
super.mouseDoubleClick(e);
}
}
});
getCommonViewer().getTree().addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
Tree tree = (Tree) e.getSource();
TreeItem[] selection = tree.getSelection();
for (TreeItem item : selection) {
Object data = item.getData();
DQRepositoryNode repoNode = (DQRepositoryNode) data;
if (RepositoryNodeHelper.canOpenEditor(repoNode)) {
OpenItemEditorAction openItemEditorAction = new OpenItemEditorAction(new IRepositoryNode[] { repoNode });
openItemEditorAction.run();
}
}
}
}
public void keyReleased(KeyEvent e) {
// do nothing here until now
}
});
// ~ADD mzhao for feature 6233 Load columns when selecting a table (or
// view) in DQ Repository view
getCommonViewer().addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
TreeSelection selection = (TreeSelection) event.getSelection();
Iterator<?> iterator = selection.iterator();
while (iterator.hasNext()) {
Object selectedElement = iterator.next();
if (selectedElement instanceof DBTableRepNode || selectedElement instanceof DBViewRepNode) {
((RepositoryNode) selectedElement).getChildren().get(0).getChildren();
}
}
}
});
// MOD mzhao 2011-03-10 bug 19147: filter MDM entries.
getCommonViewer().addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof IProject) {
return false;
}
return true;
}
});
// ~
}
Aggregations