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

The following are Jave code examples for showing how to use addKeyListener() 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: 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 2
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 3
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 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: convertigo-eclipse   File: ConvertigoPartListener.java   View Source Code Vote up 4 votes
public void partOpened(IWorkbenchPart part) {
	if (part instanceof PropertySheet) {
		PropertySheet view = (PropertySheet)part;
		if (view != null) {
			if (view.getCurrentPage().getControl() instanceof Tree) {
				Tree tree = (Tree) view.getCurrentPage().getControl();
				if (tree != null) {
					tree.addKeyListener(new KeyAdapter() {
						
						@Override
						public void keyReleased(KeyEvent event) {
							boolean bCtrl = (((event.stateMask & SWT.CONTROL) != 0) || ((event.stateMask & SWT.CTRL) != 0));
							int keyCode = event.keyCode;
							char c = event.character;
							if (bCtrl) {
								if ((c == 's') || (keyCode == 115)) {
									ProjectExplorerView projectExplorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
									if (projectExplorerView != null) {
										projectExplorerView.projectExplorerSaveAllAction.run();
									}
								}
							}
						}
						
					});
				}
			}
		}
	}
	if (part instanceof EditorPart) {
		IEditorInput input = ((EditorPart)part).getEditorInput();
		if (input instanceof ApplicationComponentEditorInput) {
			try {
				MobileBuilder mb = ((ApplicationComponentEditorInput)input).getApplication().getProject().getMobileBuilder();
				mb.addMobileEventListener((ApplicationComponentEditor)part);
				mb.setAutoBuild(true);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
 
Example 6
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();
              }
          }
      });
  }