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

The following are Jave code examples for showing how to use setMenu() of the org.eclipse.swt.widgets.Tree class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: mytourbook   File: PrefPageMap3Color.java   View Source Code Vote up 6 votes
/**
	 * create the views context menu
	 */
	private void createContextMenu() {

		final MenuManager menuMgr = new MenuManager();

		menuMgr.setRemoveAllWhenShown(true);

		menuMgr.addMenuListener(new IMenuListener() {
			@Override
			public void menuAboutToShow(final IMenuManager menuMgr2) {
//				fillContextMenu(menuMgr2);
			}
		});

		final Tree tree = _colorProfileViewer.getTree();
		final Menu treeContextMenu = menuMgr.createContextMenu(tree);

		tree.setMenu(treeContextMenu);

		_columnManager.createHeaderContextMenu(tree, treeContextMenu);
	}
 
Example 2
Project: mytourbook   File: PicDirFolder.java   View Source Code Vote up 6 votes
/**
 * create the views context menu
 */
private void createContextMenu() {

	final MenuManager menuMgr = new MenuManager();
	menuMgr.setRemoveAllWhenShown(true);
	menuMgr.addMenuListener(new IMenuListener() {
		@Override
		public void menuAboutToShow(final IMenuManager manager) {
			fillContextMenu(manager);
		}
	});

	final Tree tree = _folderViewer.getTree();
	final Menu contextMenu = menuMgr.createContextMenu(tree);

	tree.setMenu(contextMenu);

	_picDirView.registerContextMenu(MENU_ID_PIC_DIR_VIEW_IN_FOLDER, menuMgr);
}
 
Example 3
Project: fluentmark   File: MkOutlinePage.java   View Source Code Vote up 5 votes
private void createActionControls(Tree tree) {
	String outlineId = FluentMkUI.PLUGIN_ID + ".outline";
	MenuManager menuMgr = new MenuManager(outlineId, outlineId);
	menuMgr.setRemoveAllWhenShown(true);
	menuMgr.addMenuListener(new IMenuListener() {

		@Override
		public void menuAboutToShow(IMenuManager m) {
			contextMenuAboutToShow(m);
		}
	});
	menu = menuMgr.createContextMenu(tree);
	tree.setMenu(menu);

	IPageSite site = getSite();
	site.registerContextMenu(outlineId, menuMgr, viewer); // $NON-NLS-1$
	site.setSelectionProvider(viewer);

	actionGroups = new CompositeActionGroup(new ActionGroup[] { new OpenViewActionGroup(this) });

	setAction(ACTION_EXPAND, new ExpandAllAction(viewer));
	setAction(ACTION_COLLAPSE, new CollapseAllAction(viewer));
	setAction(ACTION_TOGGLE, new ToggleLinkingAction(editor));

	setAction(ACTION_COPY, new OutlineCopyAction(this));
	setAction(ACTION_CUT, new OutlineCutAction(this));
	setAction(ACTION_PASTE, new OutlinePasteAction(this));
	setAction(ACTION_DELETE, new OutlineDeleteAction(this));

	createToolBar();
}
 
Example 4
Project: mytourbook   File: KeyTreeContributor.java   View Source Code Vote up 5 votes
/**
 * Contributes actions to the tree.
 * @param treeViewer tree viewer
 */
private void contributeActions(final TreeViewer treeViewer) {
    Tree tree = treeViewer.getTree();
    
    // Add menu
    MenuManager menuManager = new MenuManager();
    Menu menu = menuManager.createContextMenu(tree);

    // Add
    final IAction addAction = new AddKeyAction(editor, treeViewer);
    menuManager.add(addAction);
    // Delete
    final IAction deleteAction = new DeleteKeyAction(editor, treeViewer);
    menuManager.add(deleteAction);
    // Rename
    final IAction renameAction = new RenameKeyAction(editor, treeViewer);
    menuManager.add(renameAction);
    
    menuManager.update(true);
    tree.setMenu(menu);
    
    // Bind actions to tree
    tree.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent event) {
            if (event.character == SWT.DEL) {
                deleteAction.run();
            } else if (event.keyCode == SWT.F2) {
                renameAction.run();
            }
        }
    });
}
 
Example 5
Project: mytourbook   File: KeyTreeContributor.java   View Source Code Vote up 5 votes
/**
 * Contributes actions to the tree.
 * @param treeViewer tree viewer
 */
private void contributeActions(final TreeViewer treeViewer) {
    Tree tree = treeViewer.getTree();
    
    // Add menu
    MenuManager menuManager = new MenuManager();
    Menu menu = menuManager.createContextMenu(tree);

    // Add
    final IAction addAction = new AddKeyAction(editor, treeViewer);
    menuManager.add(addAction);
    // Delete
    final IAction deleteAction = new DeleteKeyAction(editor, treeViewer);
    menuManager.add(deleteAction);
    // Rename
    final IAction renameAction = new RenameKeyAction(editor, treeViewer);
    menuManager.add(renameAction);
    
    menuManager.update(true);
    tree.setMenu(menu);
    
    // Bind actions to tree
    tree.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent event) {
            if (event.character == SWT.DEL) {
                deleteAction.run();
            } else if (event.keyCode == SWT.F2) {
                renameAction.run();
            }
        }
    });
}
 
Example 6
Project: mytourbook   File: KeyTreeContributor-modified.java   View Source Code Vote up 5 votes
/**
  * Contributes actions to the tree.
  * @param treeViewer tree viewer
  */
 private void contributeActions(final TreeViewer treeViewer) {
     final Tree tree = treeViewer.getTree();
     
     // Add menu
     final MenuManager menuManager = new MenuManager();
     final Menu menu = menuManager.createContextMenu(tree);

     // Add
     final IAction addAction = new AddKeyAction(editor, treeViewer);
     menuManager.add(addAction);
     // Delete
     final IAction deleteAction = new DeleteKeyAction(editor, treeViewer);
     menuManager.add(deleteAction);
     // Rename
     final IAction renameAction = new RenameKeyAction(editor, treeViewer);
     menuManager.add(renameAction);
     
     menuManager.update(true);
     tree.setMenu(menu);
     
     // Bind actions to tree
     tree.addKeyListener(new KeyAdapter() {
         @Override
public void keyReleased(final KeyEvent event) {
             if (event.character == SWT.DEL) {
                 deleteAction.run();
             } else if (event.keyCode == SWT.F2) {
                 renameAction.run();
             }
         }
     });
 }
 
Example 7
Project: mytourbook   File: KeyTreeContributor.java   View Source Code Vote up 5 votes
/**
 * Contributes actions to the tree.
 * @param treeViewer tree viewer
 */
private void contributeActions(final TreeViewer treeViewer) {
    Tree tree = treeViewer.getTree();
    
    // Add menu
    MenuManager menuManager = new MenuManager();
    Menu menu = menuManager.createContextMenu(tree);

    // Add
    final IAction addAction = new AddKeyAction(editor, treeViewer);
    menuManager.add(addAction);
    // Delete
    final IAction deleteAction = new DeleteKeyAction(editor, treeViewer);
    menuManager.add(deleteAction);
    // Rename
    final IAction renameAction = new RenameKeyAction(editor, treeViewer);
    menuManager.add(renameAction);
    
    menuManager.update(true);
    tree.setMenu(menu);
    
    // Bind actions to tree
    tree.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent event) {
            if (event.character == SWT.DEL) {
                deleteAction.run();
            } else if (event.keyCode == SWT.F2) {
                renameAction.run();
            }
        }
    });
}
 
Example 8
Project: subclipse   File: CheckoutWizardSelectionPage.java   View Source Code Vote up 4 votes
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 9
Project: PDFReporter-Studio   File: KeyTreeContributor.java   View Source Code Vote up 4 votes
/**
   * Contributes actions to the tree.
   *
   * @param treeViewer
   *            tree viewer
   */
  private void contributeActions(final TreeViewer treeViewer) {
      Tree tree = treeViewer.getTree();

      // Add menu
      MenuManager menuManager = new MenuManager();
      Menu menu = menuManager.createContextMenu(tree);

      // Add
      final IAction addAction = new AddKeyAction(editor, treeViewer);
      menuManager.add(addAction);
      // Delete
      final IAction deleteAction = new DeleteKeyAction(editor, treeViewer);
      menuManager.add(deleteAction);

      // Refactor
      final IAction refactorAction = new RefactorKeyAction(editor, treeViewer);
      menuManager.add(refactorAction);

      menuManager.update(true);
      menuManager.addMenuListener(new IMenuListener() {
	
	@Override
	public void menuAboutToShow(IMenuManager manager) {
		IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
        KeyTreeNode node = (KeyTreeNode) selection.getFirstElement();
		refactorAction.setEnabled(node != null && node.getChildren().length == 0);
		deleteAction.setEnabled(node != null);
	}
});
      tree.setMenu(menu);

      // Bind actions to tree
      tree.addKeyListener(new KeyAdapter() {
          public void keyReleased(KeyEvent event) {
              if (event.character == SWT.DEL) {
                  deleteAction.run();
              }
          }
      });
  }
 
Example 10
Project: APICloud-Studio   File: CheckoutWizardSelectionPage.java   View Source Code Vote up 4 votes
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 11
Project: ecard   File: KonsultationenView.java   View Source Code Vote up 4 votes
@Override
public void createPartControl(Composite parent){
	parent.setLayout(new GridLayout(1, false));
	Composite composite = new Composite(parent, SWT.NONE);
	composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
	TreeColumnLayout tcl_composite = new TreeColumnLayout();
	composite.setLayout(tcl_composite);
	
	treeViewer = new TreeViewer(composite, SWT.BORDER);
	Tree tree = treeViewer.getTree();
	
	TreeViewerColumn treeViewerColumn = new TreeViewerColumn(treeViewer, SWT.NONE);
	TreeColumn trclmnNewColumn = treeViewerColumn.getColumn();
	tcl_composite.setColumnData(trclmnNewColumn, new ColumnWeightData(100));
	trclmnNewColumn.setText("New Column");
	
	treeViewer.setLabelProvider(new KonsultationenTreeLabelProvider());
	treeViewer.setContentProvider(new KonsultationenTreeContentProvider(treeViewer));

	treeViewer.setInput("0");
	treeViewer.addDoubleClickListener(new KonsultationsbelegAnzeigen());
	
	MenuManager menuManager = new MenuManager();
	menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
	tree.setMenu(menuManager.createContextMenu(tree));
	
	getSite().registerContextMenu(menuManager, treeViewer);
	getSite().setSelectionProvider(treeViewer);
	
	Composite composite_1 = new Composite(parent, SWT.NONE);
	composite_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
	composite_1.setLayout(new GridLayout(4, false));
	
	Label lblOfflineNachsignaturen = new Label(composite_1, SWT.NONE);
	lblOfflineNachsignaturen.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1));
	lblOfflineNachsignaturen.setText("Gespeicherte Offline-Nachsignaturen: ");
	
	lblOFFLINENACHSIGNATUREN = new Label(composite_1, SWT.NONE);
	GridData gd_lblOFFLINENACHSIGNATUREN = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
	gd_lblOFFLINENACHSIGNATUREN.widthHint = 25;
	lblOFFLINENACHSIGNATUREN.setLayoutData(gd_lblOFFLINENACHSIGNATUREN);
	lblOFFLINENACHSIGNATUREN.setText("n/a");
	
	Label lblGespeicherteOfflineKonsultationen = new Label(composite_1, SWT.NONE);
	lblGespeicherteOfflineKonsultationen.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1));
	lblGespeicherteOfflineKonsultationen.setText("Gespeicherte Offline Konsultationen:");
	
	lblGESPEICHERTEKONSULTATIONEN = new Label(composite_1, SWT.NONE);
	GridData gd_lblGESPEICHERTEKONSULTATIONEN = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
	gd_lblGESPEICHERTEKONSULTATIONEN.widthHint = 25;
	lblGESPEICHERTEKONSULTATIONEN.setLayoutData(gd_lblGESPEICHERTEKONSULTATIONEN);
	lblGESPEICHERTEKONSULTATIONEN.setText("n/a");
	m_bindingContext = initDataBindings();
}
 
Example 12
Project: mytourbook   File: ColumnManager.java   View Source Code Vote up 4 votes
/**
 * set context menu depending on the position of the mouse
 * 
 * @param tree
 * @param defaultContextMenu
 *            can be <code>null</code>
 */
public void createHeaderContextMenu(final Tree tree, final Menu defaultContextMenu) {

	// remove old listener
	if (_treeMenuDetectListener != null) {
		tree.removeListener(SWT.MenuDetect, _treeMenuDetectListener);
	}

	final Menu headerContextMenu = createHCM_0_Menu(tree, defaultContextMenu);

	// add the context menu to the tree viewer
	_treeMenuDetectListener = new Listener() {
		@Override
		public void handleEvent(final Event event) {

			final Decorations shell = tree.getShell();
			final Display display = shell.getDisplay();

			final Point mousePosition = display.map(null, tree, new Point(event.x, event.y));

			final Rectangle clientArea = tree.getClientArea();

			final int headerHeight = tree.getHeaderHeight();
			final int headerBottom = clientArea.y + headerHeight;

			final boolean isTreeHeaderHit = clientArea.y <= mousePosition.y && mousePosition.y < headerBottom;

			_headerColumn = getHeaderColumn(tree, mousePosition, isTreeHeaderHit);

			final Menu contextMenu = getContextMenu(isTreeHeaderHit, headerContextMenu, defaultContextMenu);

			tree.setMenu(contextMenu);

			/*
			 * Set context menu position to the right border of the column
			 */
			if (_headerColumn != null) {

				int posX = _headerColumn.columnRightBorder;
				int xOffset = 0;

				final ScrollBar hBar = tree.getHorizontalBar();

				if (hBar != null) {
					xOffset = hBar.getSelection();
				}

				/*
				 * It is possible that the context menu is outside of the tree, this occures
				 * when the column is very wide and horizonal scrolled.
				 */
				if (posX - xOffset > clientArea.width) {
					posX = xOffset + clientArea.width;
				}

				final Point displayPosition = tree.toDisplay(posX, headerBottom);

				event.x = displayPosition.x - 1;
				event.y = displayPosition.y - 2;
			}
		}
	};

	tree.addListener(SWT.MenuDetect, _treeMenuDetectListener);
}