Java Code Examples for org.eclipse.swt.widgets.Tree#setMenu()

The following examples show how to use org.eclipse.swt.widgets.Tree#setMenu() . 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: AbstractContentOutlinePage.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
protected void createTreeViewerMenu() {
	Tree tree = treeViewer.getTree();
	
	String menuId = LangUIPlugin.PLUGIN_ID + ".OutlineContextMenu";
	
	MenuManager manager = new MenuManager("OutlineContextMenu", menuId);
	manager.setRemoveAllWhenShown(true);
	manager.addMenuListener(new IMenuListener() {
		@Override
		public void menuAboutToShow(IMenuManager m) {
			contextMenuAboutToShow(m);
		}
	});
	Menu treeContextMenu = manager.createContextMenu(tree);
	tree.setMenu(treeContextMenu);
	
	getSite().registerContextMenu(menuId, manager, treeViewer);
}
 
Example 2
Source File: ConnectionPopupMenuExtension.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override public void callExtensionPoint( LogChannelInterface logChannelInterface, Object extension )
  throws KettleException {
  Menu popupMenu = null;

  Tree selectionTree = (Tree) extension;
  TreeSelection[] objects = spoonSupplier.get().getTreeObjects( selectionTree );
  TreeSelection object = objects[ 0 ];
  Object selection = object.getSelection();

  if ( selection == VFSConnectionDetails.class ) {
    popupMenu = createRootPopupMenu( selectionTree );
  } else if ( selection instanceof ConnectionTreeItem ) {
    vfsConnectionTreeItem = (ConnectionTreeItem) selection;
    popupMenu = createItemPopupMenu( selectionTree );
  }

  if ( popupMenu != null ) {
    ConstUI.displayMenu( popupMenu, selectionTree );
  } else {
    selectionTree.setMenu( null );
  }
}
 
Example 3
Source File: RunConfigurationPopupMenuExtension.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override public void callExtensionPoint( LogChannelInterface logChannelInterface, Object extension )
  throws KettleException {
  Menu popupMenu = null;

  Tree selectionTree = (Tree) extension;
  TreeSelection[] objects = spoonSupplier.get().getTreeObjects( selectionTree );
  TreeSelection object = objects[ 0 ];
  Object selection = object.getSelection();

  if ( selection == RunConfiguration.class ) {
    popupMenu = createRootPopupMenu( selectionTree );
  } else if ( selection instanceof String ) {
    runConfiguration = (String) selection;
    if ( runConfiguration.equalsIgnoreCase( DefaultRunConfigurationProvider.DEFAULT_CONFIG_NAME ) ) {
      return;
    }
    popupMenu = createItemPopupMenu( selectionTree );
  }

  if ( popupMenu != null ) {
    ConstUI.displayMenu( popupMenu, selectionTree );
  } else {
    selectionTree.setMenu( null );
  }
}
 
Example 4
Source File: AbstractSegmentsStatisticsViewer.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Constructor
 *
 * @param parent
 *            the parent composite
 * @param dataProviderId
 *            the data provider extension point ID.
 * @since 3.0
 */
public AbstractSegmentsStatisticsViewer(Composite parent, @Nullable String dataProviderId) {
    super(parent, false);
    setLabelProvider(new SegmentStoreStatisticsLabelProvider());
    fTablePopupMenuManager = new MenuManager();
    fTablePopupMenuManager.setRemoveAllWhenShown(true);
    fTablePopupMenuManager.addMenuListener(manager -> {
        TreeViewer viewer = getTreeViewer();
        ISelection selection = viewer.getSelection();
        if (selection instanceof IStructuredSelection) {
            IStructuredSelection sel = (IStructuredSelection) selection;
            if (manager != null) {
                appendToTablePopupMenu(manager, sel);
            }
        }
    });
    Menu tablePopup = fTablePopupMenuManager.createContextMenu(getTreeViewer().getTree());
    Tree tree = getTreeViewer().getTree();
    tree.setMenu(tablePopup);
    tree.addDisposeListener(e -> {
        if (fModule != null) {
            fModule.dispose();
        }
    });

    fProviderId = dataProviderId;
}
 
Example 5
Source File: ViewPropertiesOutput.java    From arx with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the view.
 *
 * @param root
 */
private void create(final Composite root) {

    root.setLayout(new FillLayout());
    
    final Tree tree = new Tree(root, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    tree.setHeaderVisible(true);
    
    treeViewer = new TreeViewer(tree);
    tree.setMenu(new ClipboardHandlerTree(treeViewer).getMenu());
    
    final TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
    tree.setLinesVisible(true);
    column1.setAlignment(SWT.LEFT);
    column1.setText(Resources.getMessage("PropertiesView.1")); //$NON-NLS-1$
    column1.setWidth(160);
    final TreeColumn column2 = new TreeColumn(tree, SWT.RIGHT);
    column2.setAlignment(SWT.LEFT);
    column2.setText(Resources.getMessage("PropertiesView.2")); //$NON-NLS-1$
    column2.setWidth(100);

    treeViewer.setContentProvider(new OutputContentProvider());
    treeViewer.setLabelProvider(new OutputLabelProvider());

    treeViewer.setInput(roots);
    treeViewer.expandAll();
}
 
Example 6
Source File: Actions.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Creates a context menu with the given actions on the tree viewer.
 */
public static void bind(TreeViewer viewer, Action... actions) {
	Tree tree = viewer.getTree();
	if (tree == null)
		return;
	MenuManager menu = new MenuManager();
	for (Action action : actions)
		menu.add(action);
	tree.setMenu(menu.createContextMenu(tree));
}
 
Example 7
Source File: CheckoutWizardSelectionPage.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
public void createControl(Composite parent) {
	Composite outerContainer = new Composite(parent,SWT.NONE);
	GridLayout layout = new GridLayout();
	layout.numColumns = 1;
	outerContainer.setLayout(layout);
	outerContainer.setLayoutData(
	new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));

	treeViewer = new TreeViewer(outerContainer, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.BORDER);
	RepositoryContentProvider contentProvider = new RepositoryContentProvider();
       treeViewer.setContentProvider(contentProvider);
       treeViewer.addFilter(RepositoryFilters.FOLDERS_ONLY);
       treeViewer.setLabelProvider(new WorkbenchLabelProvider());
       treeViewer.setInput(repositoryLocation);

	GridData data = new GridData(GridData.FILL_BOTH | GridData.GRAB_VERTICAL);
	data.heightHint = LIST_HEIGHT_HINT;
	data.widthHint = LIST_WIDTH_HINT;
	treeViewer.getControl().setLayoutData(data);

	treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
		public void selectionChanged(SelectionChangedEvent event) {
			CheckoutWizard wizard = (CheckoutWizard)getWizard();
			ArrayList folderArray = new ArrayList();
			IStructuredSelection selection = (IStructuredSelection)treeViewer.getSelection();
			Iterator iter = selection.iterator();
			while (iter.hasNext()) {
				Object object = iter.next();
				if (object instanceof ISVNRemoteFolder || object instanceof ISVNRepositoryLocation) {
					if (object instanceof ISVNRepositoryLocation) folderArray.add(((ISVNRepositoryLocation)object).getRootFolder());
					else folderArray.add(object);
				}
			}
			ISVNRemoteFolder[] remoteFolders = new ISVNRemoteFolder[folderArray.size()];
			folderArray.toArray(remoteFolders);
			wizard.setRemoteFolders(remoteFolders);
			setPageComplete(!treeViewer.getSelection().isEmpty());
		}
	});
	
       final Action refreshAction = new Action(Policy.bind("RepositoriesView.refreshPopup"), SVNUIPlugin.getPlugin().getImageDescriptor(ISVNUIConstants.IMG_REFRESH)) { //$NON-NLS-1$
           public void run() {
           	refreshViewerNode();
           }
       };
       MenuManager menuMgr = new MenuManager();
       Tree tree = treeViewer.getTree();
       Menu menu = menuMgr.createContextMenu(tree);
       menuMgr.addMenuListener(new IMenuListener() {
           public void menuAboutToShow(IMenuManager manager) {
               manager.add(refreshAction);
           }

       });
       menuMgr.setRemoveAllWhenShown(true);
       tree.setMenu(menu);

	setMessage(Policy.bind("CheckoutWizardSelectionPage.text")); //$NON-NLS-1$

	setControl(outerContainer);
}
 
Example 8
Source File: ViewPropertiesInput.java    From arx with Apache License 2.0 4 votes vote down vote up
/**
 * Creates the view.
 *
 * @param root
 */
private void create(final Composite root) {

    root.setLayout(new FillLayout());
    
    Tree tree = new Tree(root, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    tree.setHeaderVisible(true);
    
    treeViewer = new TreeViewer(tree);
    tree.setMenu(new ClipboardHandlerTree(treeViewer).getMenu());
    
    final TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
    tree.setLinesVisible(true);
    column1.setAlignment(SWT.LEFT);
    column1.setText(Resources.getMessage("PropertiesView.3")); //$NON-NLS-1$
    column1.setWidth(160);
    final TreeColumn column2 = new TreeColumn(tree, SWT.RIGHT);
    column2.setAlignment(SWT.LEFT);
    column2.setText(Resources.getMessage("PropertiesView.4")); //$NON-NLS-1$
    column2.setWidth(100);
    final TreeColumn column6 = new TreeColumn(tree, SWT.RIGHT);
    column6.setAlignment(SWT.LEFT);
    column6.setText(Resources.getMessage("PropertiesView.5")); //$NON-NLS-1$
    column6.setWidth(100);
    final TreeColumn column7 = new TreeColumn(tree, SWT.RIGHT);
    column7.setAlignment(SWT.LEFT);
    column7.setText(Resources.getMessage("PropertiesView.101")); //$NON-NLS-1$
    column7.setWidth(80);
    final TreeColumn column3 = new TreeColumn(tree, SWT.RIGHT);
    column3.setAlignment(SWT.LEFT);
    column3.setText(Resources.getMessage("PropertiesView.6")); //$NON-NLS-1$
    column3.setWidth(50);
    final TreeColumn column4 = new TreeColumn(tree, SWT.RIGHT);
    column4.setAlignment(SWT.LEFT);
    column4.setText(Resources.getMessage("PropertiesView.7")); //$NON-NLS-1$
    column4.setWidth(50);
    final TreeColumn column5 = new TreeColumn(tree, SWT.RIGHT);
    column5.setAlignment(SWT.LEFT);
    column5.setText(Resources.getMessage("PropertiesView.8")); //$NON-NLS-1$
    column5.setWidth(50);
    final TreeColumn column8 = new TreeColumn(tree, SWT.RIGHT);
    column8.setAlignment(SWT.LEFT);
    column8.setText(Resources.getMessage("PropertiesView.113")); //$NON-NLS-1$
    column8.setWidth(50);
    final TreeColumn column9 = new TreeColumn(tree, SWT.RIGHT);
    column9.setAlignment(SWT.LEFT);
    column9.setText(Resources.getMessage("PropertiesView.126")); //$NON-NLS-1$
    column9.setWidth(50);

    treeViewer.setContentProvider(new InputContentProvider());
    treeViewer.setLabelProvider(new InputLabelProvider());

    treeViewer.setInput(roots);
    treeViewer.expandAll();
}