Java Code Examples for org.eclipse.swt.widgets.MenuItem#addSelectionListener()

The following examples show how to use org.eclipse.swt.widgets.MenuItem#addSelectionListener() . 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: StartSessionWithProjects.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
/** Creates a menu entry which shares projects with the given Contacts. */
private MenuItem createProjectMenuItem(
    final Menu parentMenu, final int index, final IProject project, final List<JID> contacts) {

  final MenuItem menuItem = new MenuItem(parentMenu, SWT.NONE, index);

  menuItem.setText(workbenchLabelProvider.getText(project));
  menuItem.setImage(workbenchLabelProvider.getImage(project));

  menuItem.addSelectionListener(
      new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
          CollaborationUtils.startSession(
              Collections.<IResource>singletonList(project), contacts);
        }
      });

  return menuItem;
}
 
Example 2
Source File: WorkingSetMenuContributionItem.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void fill(Menu menu, int index) {
	MenuItem mi= new MenuItem(menu, SWT.RADIO, index);

	String name= fWorkingSet.getLabel();

	mi.setText("&" + fId + " " + name);  //$NON-NLS-1$  //$NON-NLS-2$
	if (fImage == null) {
		ImageDescriptor imageDescriptor= fWorkingSet.getImageDescriptor();
		if (imageDescriptor != null)
			fImage= imageDescriptor.createImage();
	}
	mi.setImage(fImage);
	mi.setSelection(fWorkingSet.equals(fActionGroup.getWorkingSet()));
	mi.addSelectionListener(new SelectionAdapter() {
		@Override
		public void widgetSelected(SelectionEvent e) {
			IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager();
			fActionGroup.setWorkingSet(fWorkingSet, true);
			manager.addRecentWorkingSet(fWorkingSet);
		}
	});
}
 
Example 3
Source File: TextEditorContextMenuContribution.java    From git-appraise-eclipse with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void fill(Menu menu, int index) {
  MenuItem submenuItem = new MenuItem(menu, SWT.CASCADE, index);
  submenuItem.setText("&Appraise Review Comments");
  Menu submenu = new Menu(menu);
  submenuItem.setMenu(submenu);

  MenuItem reviewCommentMenuItem = new MenuItem(submenu, SWT.CHECK);
  reviewCommentMenuItem.setText("New &Review Comment...");
  reviewCommentMenuItem.addSelectionListener(createReviewCommentSelectionListener());

  MenuItem fileCommentMenuItem = new MenuItem(submenu, SWT.CHECK);
  fileCommentMenuItem.setText("New &File Comment...");
  fileCommentMenuItem.addSelectionListener(createFileCommentSelectionListener());

  MenuItem fileLineCommentMenuItem = new MenuItem(submenu, SWT.CHECK);
  fileLineCommentMenuItem.setText("New &Line Comment...");
  fileLineCommentMenuItem.addSelectionListener(createFileLineCommentSelectionListener());

  // Can only add Appraise comments if there is an active Appraise review task.
  ITask activeTask = TasksUi.getTaskActivityManager().getActiveTask();
  submenuItem.setEnabled(activeTask != null
      && AppraiseTaskMapper.APPRAISE_REVIEW_TASK_KIND.equals(activeTask.getTaskKind()));
}
 
Example 4
Source File: GroupPage.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Executed when the menu is shown: fills the group-menu
 */
@Override
public void handleEvent(Event event) {
	ProcessGrouping group = Viewers.getFirstSelected(groupViewer);
	if (group == null)
		return;
	for (MenuItem item : groupMoveMenu.getItems()) {
		item.removeSelectionListener(this);
		item.dispose();
	}
	List<ProcessGrouping> other = getOther(group);
	for (ProcessGrouping g : other) {
		MenuItem menuItem = new MenuItem(groupMoveMenu, SWT.PUSH);
		menuItem.setText(g.name);
		menuItem.setData(g);
		menuItem.addSelectionListener(this);
	}
}
 
Example 5
Source File: MenuItemProviders.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public static IMenuItemProvider ungroupColumnsMenuItemProvider() {
	return new IMenuItemProvider() {

		public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
			MenuItem columnStyleEditor = new MenuItem(popupMenu, SWT.PUSH);
			columnStyleEditor.setText("Ungroup columns");
			columnStyleEditor.setEnabled(true);

			columnStyleEditor.addSelectionListener(new SelectionAdapter() {
				@Override
				public void widgetSelected(SelectionEvent e) {
					natTable.doCommand(new UngroupColumnCommand());
				}
			});
		}
	};
}
 
Example 6
Source File: MenuItemProviders.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public static IMenuItemProvider autoResizeRowMenuItemProvider() {
	return new IMenuItemProvider() {

		public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
			MenuItem autoResizeRows = new MenuItem(popupMenu, SWT.PUSH);
			autoResizeRows.setText("Auto resize row");
			autoResizeRows.setEnabled(true);

			autoResizeRows.addSelectionListener(new SelectionAdapter() {
				@Override
				public void widgetSelected(SelectionEvent event) {
					int rowPosition = getNatEventData(event).getRowPosition();
					natTable.doCommand(new InitializeAutoResizeRowsCommand(natTable, rowPosition, natTable.getConfigRegistry(), new GC(natTable)));
				}
			});
		}
	};
}
 
Example 7
Source File: MenuItemProviders.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public static IMenuItemProvider autoResizeAllSelectedColumnMenuItemProvider() {
	return new IMenuItemProvider() {

		public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
			MenuItem autoResizeColumns = new MenuItem(popupMenu, SWT.PUSH);
			autoResizeColumns.setText("Auto resize all selected columns");
			autoResizeColumns.setEnabled(true);

			autoResizeColumns.addSelectionListener(new SelectionAdapter() {
				@Override
				public void widgetSelected(SelectionEvent event) {
					int columnPosition = getNatEventData(event).getColumnPosition();
					natTable.doCommand(new InitializeAutoResizeColumnsCommand(natTable, columnPosition, natTable.getConfigRegistry(), new GC(natTable)));
				}
			});
		}

	};
}
 
Example 8
Source File: EncodingLabel.java    From eclipse-encoding-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private void createDetectorMenuItem(final String prefValue, String label) {

		final MenuItem menuItem = new MenuItem(popupMenu, SWT.RADIO);
		menuItem.setText(format("Detector: " + label));
		menuItem.setSelection(prefValue.equals(pref(PREF_DETECTOR)));
		menuItem.addSelectionListener(new SelectionAdapter() {

			@Override
			public void widgetSelected(SelectionEvent e) {
				boolean sel = ((MenuItem) e.widget).getSelection();
				if (sel && !prefValue.equals(pref(PREF_DETECTOR))) {
					Activator.getDefault().getPreferenceStore().setValue(PREF_DETECTOR, prefValue);
					agent.getDocument().refresh();
				}
			}
		});
	}
 
Example 9
Source File: EncodingLabel.java    From eclipse-encoding-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private void createSettingMenuItem(final String prefKey, String message) {

		final MenuItem menuItem = new MenuItem(popupMenu, SWT.CHECK);
		menuItem.setText(format(message));
		menuItem.setSelection(prefIs(prefKey));
		menuItem.addSelectionListener(new SelectionAdapter() {

			@Override
			public void widgetSelected(SelectionEvent e) {
				boolean sel = !prefIs(prefKey);
				menuItem.setSelection(sel);
				Activator.getDefault().getPreferenceStore().setValue(prefKey, sel);
				agent.fireEncodingChanged();
				if (sel && prefKey.equals(PREF_AUTODETECT_CHANGE)) {
					ActiveDocument doc = agent.getDocument();
					doc.infoMessage("'Set automatically' only applies if the file properties encoding is not set.");
				}
			}
		});
	}
 
Example 10
Source File: MenuItemProviders.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public static IMenuItemProvider createColumnGroupMenuItemProvider() {
	return new IMenuItemProvider() {

		public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
			MenuItem columnStyleEditor = new MenuItem(popupMenu, SWT.PUSH);
			columnStyleEditor.setText("Create column group");
			columnStyleEditor.setEnabled(true);

			columnStyleEditor.addSelectionListener(new SelectionAdapter() {
				@Override
				public void widgetSelected(SelectionEvent e) {
					natTable.doCommand(new OpenCreateColumnGroupDialog(natTable.getShell()));
				}
			});
		}
	};
}
 
Example 11
Source File: LaborOrderPulldownMenuCreator.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Menu getMenu(final Control parent){
	if (this.menu == null) {
		this.menu = new Menu(parent);
		for (final IAction action : this.actions) {
			final MenuItem menuItem = new MenuItem(this.menu, SWT.PUSH);
			final Image image = action.getImageDescriptor().createImage();
			menuItem.setImage(image);
			menuItem.setText(action.getText());
			
			// Add listeners
			menuItem.addSelectionListener(new SelectionAdapter() {
				@Override
				public void widgetSelected(SelectionEvent e){
					select(parent, action, image);
					action.run();
				}
			});
		}
		
	}
	
	return this.menu;
}
 
Example 12
Source File: ClipboardCopy.java    From BiglyBT with GNU General Public License v2.0 5 votes vote down vote up
public static void
 addCopyToClipMenu(
final Menu					menu,
final copyToClipProvider	provider )
 {
  for ( MenuItem e: menu.getItems()){
	  
	  if ( e.getData( MENU_ITEM_KEY ) != null ){
		  
		  e.dispose();
	  }
  }
  
  MenuItem   item = new MenuItem( menu,SWT.NONE );

  item.setData( MENU_ITEM_KEY, "" );
  
  String	msg_text_id= "label.copy.to.clipboard";

  item.setText( MessageText.getString( msg_text_id ));

  item.addSelectionListener(
	  new SelectionAdapter()
	  {
		  @Override
		  public void
		  widgetSelected(
				  SelectionEvent arg0)
		  {
			  new Clipboard(menu.getDisplay()).setContents(new Object[] { provider.getText()}, new Transfer[] {TextTransfer.getInstance()});
		  }
	  });
 }
 
Example 13
Source File: ShipTable.java    From logbook with MIT License 5 votes vote down vote up
/**
 * メニューバーにメニューを追加する
 */
private void setMenuBar() {
    // メニューバーに追加する
    // フィルターメニュー
    final MenuItem filter = new MenuItem(this.opemenu, SWT.PUSH);
    filter.setText("フィルター(&F)\tCtrl+F");
    filter.setAccelerator(SWT.CTRL + 'F');
    filter.addSelectionListener((SelectedListener) (e) -> {
        int index = ShipTable.this.tabFolder.getSelectionIndex();
        new ShipFilterDialog(this.shell, this.updateFilter(index), this.getFilter(index)).open();
    });
}
 
Example 14
Source File: ClipboardCopy.java    From BiglyBT with GNU General Public License v2.0 5 votes vote down vote up
public static void
 addCopyToClipMenu(
final Menu		menu,
final String	text )
 {
  for ( MenuItem e: menu.getItems()){
	  
	  if ( e.getData( MENU_ITEM_KEY ) != null ){
		  
		  e.dispose();
	  }
  }
  
  MenuItem   item = new MenuItem( menu,SWT.NONE );

  item.setData( MENU_ITEM_KEY, "" );

  String	msg_text_id= "label.copy.to.clipboard";

  item.setText( MessageText.getString( msg_text_id ));

  item.addSelectionListener(
	  new SelectionAdapter()
	  {
		  @Override
		  public void
		  widgetSelected(
				  SelectionEvent arg0)
		  {
			  new Clipboard(menu.getDisplay()).setContents(new Object[] {text}, new Transfer[] {TextTransfer.getInstance()});
		  }
	  });
 }
 
Example 15
Source File: BlacklistedPeersPart.java    From offspring with MIT License 5 votes vote down vote up
@PostConstruct
public void postConstruct(Composite parent, INxtService nxt) {
  peerTableViewer = new PeerTableViewer(parent, nxt,
      PeerTable.TYPE_BLACKLISTED_PEERS);

  Menu contextMenu = new Menu(peerTableViewer.getTable());
  peerTableViewer.getTable().setMenu(contextMenu);

  MenuItem itemReply = new MenuItem(contextMenu, SWT.PUSH);
  itemReply.setText("Unblacklist");
  itemReply.addSelectionListener(new SelectionAdapter() {

    @Override
    public void widgetSelected(SelectionEvent e) {
      IStructuredSelection selection = (IStructuredSelection) peerTableViewer
          .getSelection();

      Iterator iter = selection.iterator();
      while (iter != null && iter.hasNext()) {
        Object element = iter.next();
        if (element instanceof Peer) {
          Peer peer = (Peer) element;
          peer.unBlacklist();
        }
      }
      peerTableViewer.refresh();
    }
  });
}
 
Example 16
Source File: QuestTable.java    From logbook with MIT License 5 votes vote down vote up
@Override
protected void createContents() {
    this.addTable(this.shell)
            .setContentSupplier(CreateReportLogic::getQuestContent)
            .reload()
            .update();

    // 任務をリセット
    final MenuItem reset = new MenuItem(this.opemenu, SWT.NONE);
    reset.setText("任務をリセット");
    reset.addSelectionListener((SelectedListener) e -> {
        GlobalContext.getQuest().clear();
        this.getSelectionTable().reload().update();
    });
}
 
Example 17
Source File: AgentsMenu.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
private static MenuItem actionAgentMenuItem(final Menu parent, final IAgent agent, final IStatement command,
		final String prefix) {
	final MenuItem result = new MenuItem(parent, SWT.PUSH);
	result.setText(prefix + " " + command.getName());
	result.setImage(GamaIcons.create(IGamaIcons.MENU_RUN_ACTION).image());
	result.addSelectionListener(runner);
	result.setData("agent", agent);
	result.setData("command", command);
	return result;
}
 
Example 18
Source File: ProjectNaturesPage.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected Menu createMenu(Table table)
{
	Menu menu = new Menu(table);
	fSetPrimaryMenuItem = new MenuItem(menu, SWT.PUSH);
	fSetPrimaryMenuItem.setText(EplMessages.ProjectNaturesPage_LBL_SetAsPrimary);
	fSetPrimaryMenuItem.addSelectionListener(this);
	return menu;
}
 
Example 19
Source File: EditorMenu.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 *
 */
private void createFoldingToggle(final Menu menu) {
	final MenuItem folding = new MenuItem(menu, SWT.CHECK);
	folding.setText(" Fold code sections");
	folding.setImage(GamaIcons.create("toggle.folding").image());
	folding.setSelection(getEditor().isRangeIndicatorEnabled());
	folding.addSelectionListener(new SelectionAdapter() {

		@Override
		public void widgetSelected(final SelectionEvent e) {
			getEditor().getAction("FoldingToggle").run();
		}
	});

}
 
Example 20
Source File: HopGuiPipelineGraph.java    From hop with Apache License 2.0 4 votes vote down vote up
private void addCandidateAsHop( int mouseX, int mouseY ) {

    boolean forward = startHopTransform != null;

    TransformMeta fromTransform = candidate.getFromTransform();
    TransformMeta toTransform = candidate.getToTransform();
    if ( fromTransform.equals( toTransform ) ) {
      return; // Don't add
    }

    // See what the options are.
    // - Does the source transform has multiple stream options?
    // - Does the target transform have multiple input stream options?
    //
    List<IStream> streams = new ArrayList<>();

    ITransformIOMeta fromIoMeta = fromTransform.getTransform().getTransformIOMeta();
    List<IStream> targetStreams = fromIoMeta.getTargetStreams();
    if ( forward ) {
      streams.addAll( targetStreams );
    }

    ITransformIOMeta toIoMeta = toTransform.getTransform().getTransformIOMeta();
    List<IStream> infoStreams = toIoMeta.getInfoStreams();
    if ( !forward ) {
      streams.addAll( infoStreams );
    }

    if ( forward ) {
      if ( fromIoMeta.isOutputProducer() && toTransform.equals( currentTransform ) ) {
        streams.add( new Stream( StreamType.OUTPUT, fromTransform, BaseMessages
          .getString( PKG, "HopGui.Hop.MainOutputOfTransform" ), StreamIcon.OUTPUT, null ) );
      }

      if ( fromTransform.supportsErrorHandling() && toTransform.equals( currentTransform ) ) {
        streams.add( new Stream( StreamType.ERROR, fromTransform, BaseMessages.getString( PKG,
          "HopGui.Hop.ErrorHandlingOfTransform" ), StreamIcon.ERROR, null ) );
      }
    } else {
      if ( toIoMeta.isInputAcceptor() && fromTransform.equals( currentTransform ) ) {
        streams.add( new Stream( StreamType.INPUT, toTransform, BaseMessages.getString( PKG, "HopGui.Hop.MainInputOfTransform" ),
          StreamIcon.INPUT, null ) );
      }

      if ( fromTransform.supportsErrorHandling() && fromTransform.equals( currentTransform ) ) {
        streams.add( new Stream( StreamType.ERROR, fromTransform, BaseMessages.getString( PKG,
          "HopGui.Hop.ErrorHandlingOfTransform" ), StreamIcon.ERROR, null ) );
      }
    }

    // Targets can be dynamically added to this transform...
    //
    if ( forward ) {
      streams.addAll( fromTransform.getTransform().getOptionalStreams() );
    } else {
      streams.addAll( toTransform.getTransform().getOptionalStreams() );
    }

    // Show a list of options on the canvas...
    //
    if ( streams.size() > 1 ) {
      // Show a pop-up menu with all the possible options...
      //
      Menu menu = new Menu( canvas );
      for ( final IStream stream : streams ) {
        MenuItem item = new MenuItem( menu, SWT.NONE );
        item.setText( Const.NVL( stream.getDescription(), "" ) );
        item.setImage( getImageFor( stream ) );
        item.addSelectionListener( new SelectionAdapter() {
          @Override
          public void widgetSelected( SelectionEvent e ) {
            addHop( stream );
          }
        } );
      }
      menu.setLocation( canvas.toDisplay( mouseX, mouseY ) );
      menu.setVisible( true );

      return;
    }
    if ( streams.size() == 1 ) {
      addHop( streams.get( 0 ) );
    } else {
      return;
    }

    /*
     *
     * if (pipelineMeta.findPipelineHop(candidate) == null) { spoon.newHop(pipelineMeta, candidate); } if (startErrorHopTransform) {
     * addErrorHop(); } if (startTargetHopStream != null) { // Auto-configure the target in the source transform... //
     * startTargetHopStream.setTransformMeta(candidate.getToTransform());
     * startTargetHopStream.setTransformName(candidate.getToTransform().getName()); startTargetHopStream = null; }
     */
    candidate = null;
    selectedTransforms = null;
    startHopTransform = null;
    endHopLocation = null;
    startErrorHopTransform = false;

    // redraw();
  }