Java Code Examples for org.eclipse.jface.viewers.TreeViewer#addDoubleClickListener()

The following examples show how to use org.eclipse.jface.viewers.TreeViewer#addDoubleClickListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActorMappingConfigurationWizardPage.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected void createMappingTree(final Composite listComposite) {
    mappingTree = new TreeViewer(listComposite, SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE | SWT.V_SCROLL);
    mappingTree.getTree().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    mappingTree.setContentProvider(new AdapterFactoryContentProvider(adapterFactory) {

        @Override
        public Object[] getElements(final Object object) {
            if (object instanceof Collection) {
                return ((Collection) object).toArray();
            }
            return super.getElements(object);
        }
    });
    mappingTree.setLabelProvider(new ActorMappingStyledTreeLabelProvider(adapterFactory, deployedOrganization));
    mappingTree.addSelectionChangedListener(this);
    mappingTree.addDoubleClickListener(this);
    mappingTree.addFilter(new ViewerFilter() {

        @Override
        public boolean select(final Viewer viewer, final Object parentElement, final Object element) {
            return (element instanceof String || element instanceof MembershipType)
                    || ((ITreeContentProvider) mappingTree.getContentProvider()).hasChildren(element);
        }
    });
}
 
Example 2
Source File: QueryEditionControl.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private TreeViewer createQueryViewer(Composite parent) {
    TreeViewer queryViewer = new TreeViewer(parent,
            SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE);
    queryViewer.getTree()
            .setLayoutData(GridDataFactory.fillDefaults().grab(false, true).hint(300, SWT.DEFAULT).create());
    queryViewer.getTree().setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY, QUERY_LIST_VIEWER_ID);
    formPage.getToolkit().adapt(queryViewer.getTree());
    ColumnViewerToolTipSupport.enableFor(queryViewer);
    queryViewer.setUseHashlookup(true);
    queryViewer.addFilter(createSearchFilter());
    queryViewer.addDoubleClickListener(e -> {
        queryViewer.setExpandedState(querySelectedObservable.getValue(),
                !viewer.getExpandedState(querySelectedObservable.getValue()));
    });

    TableLayout layout = new TableLayout();
    layout.addColumnData(new ColumnWeightData(1, true));
    queryViewer.getTree().setLayout(layout);

    createQueryNameColumn(queryViewer);

    provider = new QueryContentProvider();
    queryViewer.setContentProvider(provider);
    return queryViewer;
}
 
Example 3
Source File: BusinessObjectList.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected void createViewer(Composite parent, AbstractBdmFormPage formPage) {
    viewer = new TreeViewer(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    viewer.getTree().setLayoutData(GridDataFactory.fillDefaults().span(2, 1).grab(true, true).create());
    formPage.getToolkit().adapt(viewer.getTree());
    viewer.getTree().setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY, BUSINESS_OBJECT_LIST_VIEWER_ID);
    viewer.addFilter(createSearchFilter());
    viewer.addDoubleClickListener(e -> {
        viewer.setExpandedState(selectionObservable.getValue(),
                !viewer.getExpandedState(selectionObservable.getValue()));
    });

    ColumnViewerToolTipSupport.enableFor(viewer);
    TableLayout layout = new TableLayout();
    layout.addColumnData(new ColumnWeightData(1, true));
    viewer.getTree().setLayout(layout);
    viewer.setUseHashlookup(true);
    createBusinessObjectColumn(viewer, formPage);
    viewer.setContentProvider(new BusinessObjectTreeContentProvider());
    viewer.setComparator(new BusinessObjectViewerComparator());
    viewer.setInput(input);
    addDNDSupport(formPage);
    selectionObservable = ViewerProperties.singleSelection(Object.class).observe(viewer);
}
 
Example 4
Source File: AbapGitStagingView.java    From ADT_Frontend with MIT License 5 votes vote down vote up
private void addDoubleClickListener(TreeViewer viewer) {
	viewer.addDoubleClickListener((event) -> {
		//open the object
		if (event.getSelection() instanceof IStructuredSelection) {
			IStructuredSelection selection = (IStructuredSelection) event.getSelection();
			Object object = selection.getFirstElement();
			this.stagingUtil.openEditor(object, this.project, this.repositoryCredentials);
		}
	});
}
 
Example 5
Source File: DriverSelectionDialog.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Control createDialogArea ( final Composite parent )
{
    setTitle ( "Select driver" );
    setMessage ( "Choose a driver from the world model" );

    final Composite composite = (Composite)super.createDialogArea ( parent );

    final ObservablesManager mgr = new ObservablesManager ();

    final TreeViewer viewer = new TreeViewer ( composite );
    viewer.setAutoExpandLevel ( 2 );
    viewer.getControl ().setLayoutData ( new GridData ( SWT.FILL, SWT.FILL, true, true ) );
    viewer.addDoubleClickListener ( new IDoubleClickListener () {

        @Override
        public void doubleClick ( final DoubleClickEvent event )
        {
            handleDoubleClick ();
        }
    } );

    mgr.runAndCollect ( new Runnable () {

        @Override
        public void run ()
        {
            createDataModel ( viewer );
        }
    } );

    return composite;
}
 
Example 6
Source File: JsonTreeViewer.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
protected TreeViewer createViewer(Composite parent) {
	TreeViewer viewer = new TreeViewer(parent, SWT.MULTI | SWT.NO_FOCUS | SWT.HIDE_SELECTION | SWT.BORDER);
	viewer.setContentProvider(new ContentProvider());
	Tree tree = viewer.getTree();
	if (viewerParameters[0] == Site.LOCAL)
		tree.getVerticalBar().setVisible(false);
	UI.gridData(tree, true, true);
	viewer.addDoubleClickListener((e) -> onDoubleClick(e));
	return viewer;
}
 
Example 7
Source File: LaunchConfigurationContent.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private void createViewer(Label launchUrlsCaptionLabel) {
  viewer = new TreeViewer(this, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
  viewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
  viewer.setLabelProvider(new LabelProvider());
  viewer.setContentProvider(new ContentProvider(launchUrlsCaptionLabel));
  viewer.setInput(launchConfiguration);
  viewer.addDoubleClickListener(new IDoubleClickListener() {
    @Override
    public void doubleClick(DoubleClickEvent event) {
      browserMenuPopulator.openDefaultBrowser(getProject(launchConfiguration), getSelectedUrl());
    }
  });
}
 
Example 8
Source File: DialogPackageExplorer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public Control createControl(Composite parent) {
    fPackageViewer= new TreeViewer(parent, SWT.MULTI);
    fPackageViewer.setComparer(WorkingSetModel.COMPARER);
    fPackageViewer.addFilter(new PackageFilter());
    fPackageViewer.setComparator(new ExtendedJavaElementSorter());
    fPackageViewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            Object element= ((IStructuredSelection)event.getSelection()).getFirstElement();
            if (fPackageViewer.isExpandable(element)) {
                fPackageViewer.setExpandedState(element, !fPackageViewer.getExpandedState(element));
            } else {
            	if (element instanceof CPListElementAttribute) {
		CPListElementAttribute attribute= (CPListElementAttribute)element;
            		if (attribute.getKey().equals(CPListElement.OUTPUT)) {
            			fActionGroup.getEditOutputFolderAction().run();
            		}
            	}
            }
        }
    });

    MenuManager menuMgr= new MenuManager("#PopupMenu"); //$NON-NLS-1$
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(this);
    fContextMenu= menuMgr.createContextMenu(fPackageViewer.getTree());
    fPackageViewer.getTree().setMenu(fContextMenu);
    parent.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            fContextMenu.dispose();
        }
    });

    return fPackageViewer.getControl();
}
 
Example 9
Source File: Navigator.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
protected void initListeners(TreeViewer viewer) {
	super.initListeners(viewer);
	viewer.setUseHashlookup(true);
	ColumnViewerToolTipSupport.enableFor(viewer);
	viewer.addDoubleClickListener(evt -> {
		var elem = Viewers.getFirst(evt.getSelection());
		if (elem instanceof ModelElement) {
			var model = ((ModelElement) elem).getContent();
			App.openEditor(model);
		} else if (elem instanceof DatabaseElement) {
			var config = ((DatabaseElement) elem).getContent();
			if (config != null && !Database.isActive(config)) {
				new DbActivateAction(config).run();
			}
		} else if (elem instanceof ScriptElement) {
			var file = ((ScriptElement) elem).getContent();
			if (file.isDirectory())
				return;
			if (file.getName().endsWith(".py")) {
				PythonEditor.open(file);
			}
		} else if (elem instanceof LibraryElement) {
			var library = ((LibraryElement) elem).getContent();
			LibraryInfoPage.show(library);
		}
	});
}
 
Example 10
Source File: SmartImportBdmPage.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private Composite createMergeViewer(Composite parent) {
    Composite composite = new Composite(parent, SWT.None);
    composite.setLayout(GridLayoutFactory.fillDefaults().spacing(LayoutConstants.getSpacing().x, 1).create());
    composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

    viewer = new TreeViewer(composite,
            SWT.VIRTUAL | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
    viewer.getTree().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    viewer.setUseHashlookup(true);
    ColumnViewerToolTipSupport.enableFor(viewer);
    viewer.getTree().setHeaderVisible(true);
    viewer.getTree().setLinesVisible(true);
    viewer.setContentProvider(new SmartImportBdmTreeContentProvider());

    TableLayout layout = new TableLayout();
    layout.addColumnData(new ColumnWeightData(6, true));
    layout.addColumnData(new ColumnWeightData(2, true));
    viewer.getTree().setLayout(layout);

    createModelColumn();
    createActionColumn();

    IViewerObservableValue singleSelectionObservable = ViewerProperties.singleSelection().observe(viewer);
    viewer.addDoubleClickListener(e -> viewer.setExpandedState(singleSelectionObservable.getValue(),
            !viewer.getExpandedState(singleSelectionObservable.getValue())));
    return composite;
}
 
Example 11
Source File: AbstractManageDiagramWizardPage.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected Composite doCreateControl(final Composite parent, final DataBindingContext context) {
    final Composite mainComposite = new Composite(parent, SWT.NONE);
    mainComposite.setLayout(fillDefaults().numColumns(2).equalWidth(true).create());

    diagramTree = new FilteredTree(mainComposite, SWT.MULTI | SWT.BORDER, new PatternFilter(), false);
    final TreeViewer treeViewer = diagramTree.getViewer();
    treeViewer.getTree().setData(SWTBOT_WIDGET_ID_KEY, SWTBOT_ID_OPEN_DIAGRAM_TREE_ID);
    diagramTree
            .setLayoutData(GridDataFactory.fillDefaults().grab(true, true).span(2, 1).hint(SWT.DEFAULT, 250).create());

    treeViewer.setContentProvider(
            new ObservableListTreeContentProvider(diagramListObservableFactory(), diagramTreeStructure()));
    treeViewer.setLabelProvider(new DiagramLabelProvider(new FileStoreLabelProvider()));

    final IObservableList selectionObservable = PojoObservables.observeList(this, "selectedDiagrams");
    context.bindList(ViewersObservables.observeMultiSelection(diagramTree.getViewer()),
            selectionObservable);
    context.addValidationStatusProvider(new MultiValidator() {

        @Override
        protected IStatus validate() {
            return selectionObservable.isEmpty() ? ValidationStatus.error(Messages.noDiagramSelected)
                    : ValidationStatus.ok();
        }
    });
    treeViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(final DoubleClickEvent arg0) {
            final IWizard wizard = getWizard();
            if (wizard.canFinish() && wizard.performFinish() && wizard.getContainer() instanceof WizardDialog) {
                ((WizardDialog) wizard.getContainer()).close();
            }
        }
    });
    treeViewer.setInput(diagramRepositoryStore);
    treeViewer.getTree().setFocus();
    defaultSelection(selectionObservable);
    return mainComposite;
}
 
Example 12
Source File: FlowRefDialog.java    From olca-app with Mozilla Public License 2.0 4 votes vote down vote up
@Override
protected void createFormContent(IManagedForm mform) {
	FormToolkit tk = mform.getToolkit();
	Composite body = UI.formBody(mform.getForm(), tk);
	UI.gridLayout(body, 1, 10, 10);

	Composite filterComp = tk.createComposite(body);
	UI.gridLayout(filterComp, 2, 10, 0);
	UI.gridData(filterComp, true, false);
	Label filterLabel = UI.formLabel(filterComp, tk, M.Filter);
	filterLabel.setFont(UI.boldFont());
	Text filterText = UI.formText(filterComp, SWT.SEARCH);
	UI.gridData(filterText, true, false);

	TreeViewer viewer = new TreeViewer(body,
			SWT.BORDER | SWT.SINGLE | SWT.VIRTUAL);
	UI.gridData(viewer.getControl(), true, true);
	viewer.setContentProvider(tree);
	viewer.setLabelProvider(tree);
	viewer.setFilters(new Filter(filterText, viewer));
	viewer.setInput(tree);

	viewer.addSelectionChangedListener(e -> {
		Object obj = Viewers.getFirst(e.getSelection());
		if (obj instanceof FlowRef) {
			selected = (FlowRef) obj;
		} else {
			selected = null;
		}
		Button ok = getButton(IDialogConstants.OK_ID);
		ok.setEnabled(selected != null);
	});

	// handle double clicks
	viewer.addDoubleClickListener(e -> {
		IStructuredSelection s = viewer.getStructuredSelection();
		if (s == null || s.isEmpty())
			return;
		Object elem = s.getFirstElement();

		// double click on a flow
		if (elem instanceof FlowRef) {
			selected = (FlowRef) elem;
			okPressed();
			return;
		}

		// double click on a category
		if (!tree.hasChildren(elem))
			return;
		selected = null;
		getButton(IDialogConstants.OK_ID).setEnabled(false);
		if (viewer.getExpandedState(elem)) {
			viewer.collapseToLevel(elem,
					AbstractTreeViewer.ALL_LEVELS);
		} else {
			viewer.expandToLevel(elem, 1);
		}
	});
}
 
Example 13
Source File: DiffTreeViewer.java    From olca-app with Mozilla Public License 2.0 4 votes vote down vote up
protected void configureViewer(TreeViewer viewer, boolean checkable) {
	viewer.setContentProvider(new ContentProvider());
	viewer.setComparator(new Comparator());
	viewer.addDoubleClickListener(this::onDoubleClick);
}
 
Example 14
Source File: ICEResourceView.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * This operation overrides the ViewPart.createPartControl method to create
 * and draw the TreeViewer before registering it as a selection provider.
 * 
 * @param parent
 *            The Composite used to create the TreeViewer.
 */
@Override
public void createPartControl(Composite parent) {

	// Create a TabFolder to manage tabs
	tabFolder = new TabFolder(parent, SWT.NONE);

	// Create pages (TabItems) for text files and images
	TabItem textTab = new TabItem(tabFolder, SWT.NONE, 0);
	textTab.setText("Files");
	TabItem imageTab = new TabItem(tabFolder, SWT.NONE, 1);
	imageTab.setText("Images");
	TabItem plotTab = new TabItem(tabFolder, SWT.NONE, 2);
	plotTab.setText("Plots");

	// Create the tool bar and buttons for the view
	createActions();

	// Initialize the TreeViewer
	fileTreeViewer = new TreeViewer(tabFolder);
	imageTreeViewer = new TreeViewer(tabFolder);
	// Create content and label providers
	initializeTreeViewer(fileTreeViewer);
	initializeTreeViewer(imageTreeViewer);
	// Register the tree to the tabs
	textTab.setControl(fileTreeViewer.getControl());
	imageTab.setControl(imageTreeViewer.getControl());
	// Register this view as a SelectionProvider
	getSite().setSelectionProvider(fileTreeViewer);
	getSite().setSelectionProvider(imageTreeViewer);
	// Registered the view as a double click listener of the TreeViewer
	fileTreeViewer.addDoubleClickListener(this);
	imageTreeViewer.addDoubleClickListener(this);

	// Add a listener to catch tab selection changes.
	// NOTE: In Windows, this event is fired instantly, so this listener
	// needs to be declared after everything else is initialized!
	tabFolder.addListener(SWT.Selection, new Listener() {
		@Override
		public void handleEvent(Event event) {
			// If tabs are changed while playing, stop playing.
			if (playAction.isInPlayState()) {
				playAction.stop();
			}
			// Set the TreeViewer input to the selected tab
			setTreeContent(tabFolder.indexOf((TabItem) event.item));
		}
	});

	// Create the Table and table viewer for the Plot tab
	Table listTable = new Table(tabFolder, SWT.FLAT);
	DefaultEventTableViewer<VizResource> listTableViewer = new DefaultEventTableViewer<VizResource>(
			plotList, listTable, plotList);
	// Register the table control with the plot tab
	plotTab.setControl(listTable);

	// Check if there is currently an active ICEFormEditor. If so, update
	// the currently active editor and related UI pieces.
	IEditorPart activeEditor = PlatformUI.getWorkbench()
			.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
	if (activeEditor != null && activeEditor instanceof ICEFormEditor) {
		if (activeEditor != editor) {
			setActiveEditor((ICEFormEditor) activeEditor);
		}
	} else {
		// Get a list of all the currently open editors
		IWorkbenchPage workbenchPage = PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow().getActivePage();
		IEditorReference[] editorRefs = workbenchPage.getEditorReferences();

		if (editorRefs != null && editorRefs.length > 0) {
			// Begin iterating through all the editors, looking for one
			// that's an ICEFormEditor
			for (IEditorReference e : editorRefs) {
				// If it's an ICEFormEditor, set it as the active editor
				if (e.getId().equals(ICEFormEditor.ID)) {
					setActiveEditor((ICEFormEditor) e.getEditor(false));
					break;
				}
			}
		}
	}

	// Register as a listener to the part service so that the view can
	// update when the active ICEFormEditor changes.
	IPartService partService = getSite().getWorkbenchWindow()
			.getPartService();
	partService.addPartListener(this);

	return;
}
 
Example 15
Source File: TSVEditor.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 4 votes vote down vote up
void createPage1() {
	Composite composite = new Composite(getContainer(), SWT.NONE);
	FillLayout layout = new FillLayout();
	composite.setLayout(layout);
	
	Tree tree = new Tree(composite, SWT.BORDER | SWT.H_SCROLL
			| SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI);
	tree.setHeaderVisible(true);
	tree.setLinesVisible(true);
	TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
	column1.setWidth(250);
	column1.setResizable(true);
	TreeColumn column2 = new TreeColumn(tree, SWT.LEFT);
	column2.setWidth(40);
	column2.setResizable(true);
	TreeColumn column3 = new TreeColumn(tree, SWT.LEFT);
	column3.setWidth(250);
	column3.setResizable(true);
	TreeColumn column4 = new TreeColumn(tree, SWT.LEFT);
	column4.setWidth(600);
	column4.setResizable(true);
	
	TreeViewer resultsViewer = new TreeViewer(tree);
	resultsViewer.setLabelProvider(new TSVResultsLabelProvider());
	resultsViewer.setContentProvider(new TSVResultsContentProvider(resultMap));
	resultsViewer.setInput(createModel());
	
	resultsViewer.addDoubleClickListener(new IDoubleClickListener() {
		@Override
		public void doubleClick(DoubleClickEvent event) {
			
			IStructuredSelection structuredSelection = (IStructuredSelection) event.getSelection();
	        if (structuredSelection.isEmpty()) return;

	        Object selection = structuredSelection.getFirstElement();
	        
	        if (selection instanceof TSVResult) {
	        	String fileName = ((TSVResult) selection).getFilename();
	        	int lineNumber = ((TSVResult) selection).getLineNumber();
	        	String extensionName = fileName.replaceAll("-items.xml", "");
	        		
	        	IProject extension = ResourcesPlugin.getWorkspace().getRoot().getProject(extensionName);
	        	IFile itemsxml = extension.getFile("resources/" + fileName);
	        	if (itemsxml.exists()) {
		        	IMarker marker;
		        	try {
						marker = itemsxml.createMarker(IMarker.TEXT);
						HashMap<String, Object> map = new HashMap<String, Object>();
						map.put(IMarker.LINE_NUMBER, lineNumber);
						marker.setAttributes(map);
						IDE.openEditor(getSite().getPage(), marker);
						marker.delete();
					}
		        	catch (CoreException e) {
						e.printStackTrace();
					}
	        	}
	        	else {
	        		MessageBox dialog = new MessageBox(getContainer().getShell(), SWT.ICON_WARNING | SWT.OK);
	        		dialog.setText("Extension not found");
	        		dialog.setMessage("The extension " + extensionName + " was not found in the workspace. Please import it and try again.");
	        		dialog.open();
	        	}
	        }
		}
		
	});

	int index = addPage(composite);
	setPageText(index, "Results");
}
 
Example 16
Source File: CodeRecommendationResultsView.java    From scava with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Create the composite.
 * 
 * @param parent
 * @param style
 */
public CodeRecommendationResultsView() {
	super(SWT.NONE);
	setBackgroundMode(SWT.INHERIT_FORCE);
	setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
	setLayout(new FillLayout(SWT.HORIZONTAL));

	treeViewer = new TreeViewer(this, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
	treeViewer.setAutoExpandLevel(3);
	Tree tree = treeViewer.getTree();
	tree.setHeaderVisible(true);

	TreeViewerColumn treeViewerColumn = new TreeViewerColumn(treeViewer, SWT.NONE);
	TreeColumn trclmnCodeRecommendations = treeViewerColumn.getColumn();
	trclmnCodeRecommendations.setResizable(false);
	trclmnCodeRecommendations.setText("Code recommendations");

	treeViewer.setContentProvider(contentProvider = new TreeContentProvider());
	treeViewer.setLabelProvider(new DelegatingStyledCellLabelProvider(labelProvider = new TreeLabelProvider()));

	tree.addSelectionListener(new SelectionAdapter() {
		@Override
		public void widgetSelected(SelectionEvent e) {
			TreeItem item = (TreeItem) e.item;
			Object data = item.getData();

			if (data instanceof ICodeRecommendationElement) {
				ICodeRecommendationElement element = (ICodeRecommendationElement) data;
				eventManager.invoke(l -> l.onCodeRecommendationSelected(element));
			}
		}
	});

	treeViewer.addDoubleClickListener(new IDoubleClickListener() {
		@Override
		public void doubleClick(DoubleClickEvent event) {
			TreeViewer viewer = (TreeViewer) event.getViewer();
			IStructuredSelection thisSelection = (IStructuredSelection) event.getSelection();
			Object selectedNode = thisSelection.getFirstElement();
			if (selectedNode instanceof CodeRecommendationTarget) {
				CodeRecommendationTarget target = (CodeRecommendationTarget) selectedNode;

				eventManager.invoke(l -> l.onTargetDoubleClicked(target));
			}
		}
	});

	createContextMenu(treeViewer);
}
 
Example 17
Source File: MasterSelectionDialog.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected Control createDialogArea ( final Composite parent )
{
    setTitle ( "Select master server" );
    setMessage ( "Choose a master server from the world model" );

    final Composite composite = (Composite)super.createDialogArea ( parent );

    final Composite wrapper = new Composite ( composite, SWT.NONE );
    wrapper.setLayout ( new GridLayout ( 1, true ) );
    wrapper.setLayoutData ( new GridData ( SWT.FILL, SWT.FILL, true, true ) );

    final ObservablesManager mgr = new ObservablesManager ();

    final TreeViewer viewer = new TreeViewer ( wrapper );
    viewer.setAutoExpandLevel ( 2 );
    viewer.getControl ().setLayoutData ( new GridData ( SWT.FILL, SWT.FILL, true, true, 1, 1 ) );
    viewer.addDoubleClickListener ( new IDoubleClickListener () {

        @Override
        public void doubleClick ( final DoubleClickEvent event )
        {
            handleDoubleClick ();
        }
    } );

    final Button add = new Button ( wrapper, SWT.RADIO );
    add.setText ( "Add master server" );
    add.setToolTipText ( "Assign the component to the selected master server in addition" );

    this.replace = new Button ( wrapper, SWT.RADIO );
    this.replace.setText ( "Replace all master servers" );
    this.replace.setToolTipText ( "Assign the component soley to the selected master server" );
    this.replace.setSelection ( true );

    this.delete = new Button ( wrapper, SWT.RADIO );
    this.delete.setText ( "Remove master server" );
    this.delete.setToolTipText ( "Un-assign the component from the selected master server" );

    mgr.runAndCollect ( new Runnable () {

        @Override
        public void run ()
        {
            createDataModel ( viewer );
        }
    } );

    if ( this.lastSelection != null )
    {
        viewer.setSelection ( new StructuredSelection ( this.lastSelection ) );
        viewer.reveal ( this.lastSelection );
    }

    return composite;
}