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

The following examples show how to use org.eclipse.swt.widgets.MenuItem#setSelection() . 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: 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 2
Source File: ContactSorterSwitcher.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void fill(Menu menu, int index){
	for (final ContactSelectorViewerComparator.sorter sortMethod : ContactSelectorViewerComparator.sorter
		.values()) {
		MenuItem temp = new MenuItem(menu, SWT.CHECK, index);
		temp.setData(sortMethod);
		temp.setText(sortMethod.label);
		temp.setSelection(ContactSelectorViewerComparator.getSelectedSorter()
			.equals(sortMethod));
		temp.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e){
				ContactSelectorViewerComparator.setSelectedSorter(sortMethod);
			}
		});
	}
}
 
Example 3
Source File: ModeMenu.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
@Override
protected void insertAction(final Type type, Menu parentMenu) {
  MenuItem actionItem = new MenuItem(parentMenu, SWT.CHECK);
  actionItem.setText(type.getName());
  
  if (type.equals(editor.getAnnotationMode()))
      actionItem.setSelection(true);
  
  actionItem.addListener(SWT.Selection, new Listener() {
    @Override
    public void handleEvent(Event e) {

  	for (IModeMenuListener listener : listeners) {
  		listener.modeChanged(type);
  	}
    }
  });
}
 
Example 4
Source File: ExpressionCellEditor.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void showMenu( )
{
	if ( menu != null )
	{
		Rectangle size = button.getBounds( );
		menu.setLocation( button.toDisplay( new Point( 0, size.height - 1 ) ) );

		for ( int i = 0; i < menu.getItemCount( ); i++ )
		{
			MenuItem item = menu.getItem( i );
			if ( item.getData( ).equals( getExpressionType( ) ) )
				item.setSelection( true );
			else
				item.setSelection( false );
		}
		menu.setVisible( true );
	}
}
 
Example 5
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 6
Source File: CustomFiltersActionGroup.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.CHECK, index);
			mi.setText("&" + fItemNumber + " " + fFilterName);  //$NON-NLS-1$  //$NON-NLS-2$
			/*
			 * XXX: Don't set the image - would look bad because other menu items don't provide image
			 * XXX: Get working set specific image name from XML - would need to cache icons
			 */
//			mi.setImage(JavaPluginImages.get(JavaPluginImages.IMG_OBJS_JAVA_WORKING_SET));
			mi.setSelection(fState);
			mi.addSelectionListener(new SelectionAdapter() {
				@Override
				public void widgetSelected(SelectionEvent e) {
					fState= !fState;
					fActionGroup.setFilter(fFilterId, fState);
				}
			});
		}
 
Example 7
Source File: EditorMenu.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
private void createOverviewToggle(final Menu menu) {
	final MenuItem overview = new MenuItem(menu, SWT.CHECK);
	overview.setText(" Show markers overview");
	overview.setSelection(getEditor().isOverviewRulerVisible());
	overview.setImage(GamaIcons.create("toggle.overview").image());
	overview.addSelectionListener(new SelectionAdapter() {

		@Override
		public void widgetSelected(final SelectionEvent e) {
			final boolean shown = getEditor().isOverviewRulerVisible();
			if (shown) {
				getEditor().hideOverviewRuler();
			} else {
				getEditor().showOverviewRuler();
			}
		}
	});

}
 
Example 8
Source File: EditorMenu.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
private void createBoxToggle(final Menu menu) {
	final MenuItem box = new MenuItem(menu, SWT.CHECK);
	box.setText(" Colorize code sections");
	box.setImage(GamaIcons.create("toggle.box").image());
	box.setSelection(getEditor().isDecorationEnabled());
	box.addSelectionListener(new SelectionAdapter() {

		@Override
		public void widgetSelected(final SelectionEvent e) {
			final boolean selection = box.getSelection();
			getEditor().setDecorationEnabled(selection);
			getEditor().decorate(selection);
		}
	});

}
 
Example 9
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 10
Source File: EditorMenu.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 *
 */
private void createMarkToggle(final Menu menu) {
	final MenuItem mark = new MenuItem(menu, SWT.CHECK);
	mark.setText(" Mark occurences of symbols");
	mark.setImage(GamaIcons.create("toggle.mark").image());
	mark.setSelection(markPref.getValue());
	mark.addSelectionListener(new SelectionAdapter() {

		@Override
		public void widgetSelected(final SelectionEvent e) {
			markPref.set(mark.getSelection()).save();
		}
	});

}
 
Example 11
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 12
Source File: EditorMenu.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 *
 */
private void createLineToggle(final Menu menu) {
	final MenuItem line = new MenuItem(menu, SWT.CHECK);
	line.setText(" Display line number");
	line.setImage(GamaIcons.create("toggle.numbers").image());
	line.setSelection(getEditor().isLineNumberRulerVisible());
	line.addSelectionListener(new SelectionAdapter() {

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

}
 
Example 13
Source File: GamaMenu.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public static final MenuItem check(final Menu m, final String s, final boolean select,
		final SelectionListener listener, final Image image) {
	final MenuItem action = createItem(m, SWT.CHECK);
	action.setText(s);
	action.setSelection(select);
	action.addSelectionListener(listener);
	if (image != null) {
		action.setImage(image);
	}
	return action;
}
 
Example 14
Source File: SeverityClassificationPulldownAction.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Reset menu items so they are unchecked.
 *
 * @param enable
 *            true if menu items should be enabled, false if they should be
 *            disabled
 */
private void resetMenuItems(boolean enable) {
    for (int i = 0; i < severityItemList.length; ++i) {
        MenuItem menuItem = severityItemList[i];
        menuItem.setEnabled(enable);
        menuItem.setSelection(false);
    }
}
 
Example 15
Source File: SeverityClassificationPulldownAction.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Set the menu to given severity level.
 *
 * @param severity
 *            the severity level (1..5)
 */
private void selectSeverity(int severity) {
    // Severity is 1-based, but the menu item list is 0-based
    int index = severity - 1;

    for (int i = 0; i < severityItemList.length; ++i) {
        MenuItem menuItem = severityItemList[i];
        menuItem.setEnabled(true);
        menuItem.setSelection(i == index);
    }
}
 
Example 16
Source File: LineSeparatorLabel.java    From eclipse-encoding-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private void createSelectionMenu() {

		final ActiveDocument doc = agent.getDocument();
		boolean nonDirty = !agent.isDocumentDirty() && doc.canConvertContent();

		for (final SeparatorItem separatorItem : separatorItemList) {

			final MenuItem menuItem = new MenuItem(popupMenu, SWT.RADIO);
			menuItem.setText(separatorItem.value + " " + separatorItem.desc);
			menuItem.setEnabled(nonDirty);
			// Allow change if detectedEncoding is null for english only
			if (prefIs(PREF_DISABLE_DISCOURAGED_OPERATION) && doc.mismatchesEncoding()) {
				menuItem.setEnabled(false);
			}
			if (separatorItem.value.equals(doc.getLineSeparator())) {
				menuItem.setSelection(true);
			}
			menuItem.setImage(Activator.getImage(separatorItem.value));

			menuItem.addSelectionListener(new SelectionAdapter() {
				@Override
				public void widgetSelected(SelectionEvent e) {
					doc.setLineSeparator(separatorItem.value);
				}
			});
		}
	}
 
Example 17
Source File: ShowAnnotationsMenu.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
protected void insertAction(final Type type, Menu parentMenu) {
	final MenuItem actionItem = new MenuItem(parentMenu, SWT.CHECK);
	actionItem.setText(type.getName());

	// TODO: find another way to select the annotation mode also
	if (editorAnnotationMode != null && editorAnnotationMode.equals(type)) {
		actionItem.setSelection(true);
	}

	if (typesToDisplay.contains(type)) {
		actionItem.setSelection(true);
	}

	// TODO: move this to an action
	// do not access mTypesToDisplay directly !!!
	actionItem.addListener(SWT.Selection, new Listener() {
		@Override
     public void handleEvent(Event e) {
			if (actionItem.getSelection()) {
				typesToDisplay.add(type);

			} else {
				typesToDisplay.remove(type);
			}

			fireChanged();
		}
	});
}
 
Example 18
Source File: AnnotationEditor.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public void fill(Menu parentMenu, int index) {
  
  CAS cas = casEditor.getDocument().getCAS();
  
  for (Iterator<CAS> it = cas.getViewIterator(); it.hasNext(); ) {
    
    CAS casView = it.next();
    final String viewName = casView.getViewName();
    
    final MenuItem actionItem = new MenuItem(parentMenu, SWT.CHECK);
    actionItem.setText(viewName);
    
    // TODO: Disable non-text views, check mime-type
    try {
      actionItem.setEnabled(cas.getDocumentText() != null);
    } catch (Throwable t) {
      // TODO: Not nice, discuss better solution on ml
      actionItem.setEnabled(false); 
    }
    
    // TODO: Add support for non text views, editor has
    //       to display some error message
    
    if (cas.getViewName().equals(viewName))
        actionItem.setSelection(true);
    
    // TODO: move this to an action
    actionItem.addListener(SWT.Selection, new Listener() {
      @Override
      public void handleEvent(Event e) {
        // Trigger only if view is really changed
        // TODO: Move this check to the document itself ...
        if(!casEditor.getDocument().getCAS().getViewName().equals(viewName)) {
            casEditor.showView(viewName);
        }
      }
    });
  }
}
 
Example 19
Source File: LayoutMenuAction.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private Menu createMenu(Menu menu) {
	MenuItem treeItem = new MenuItem(menu, SWT.RADIO);
	treeItem.setText(treeLayoutAction.getText());
	Controls.onSelect(treeItem, (e) -> treeLayoutAction.run());
	treeItem.setSelection(true);
	MenuItem minimalItem = new MenuItem(menu, SWT.RADIO);
	minimalItem.setText(minimalLayoutAction.getText());
	Controls.onSelect(treeItem, (e) -> minimalLayoutAction.run());
	new MenuItem(menu, SWT.SEPARATOR);
	MenuItem routedCheck = new MenuItem(menu, SWT.CHECK);
	routedCheck.setText(M.Route);
	routedCheck.setSelection(editor.isRouted());
	Controls.onSelect(routedCheck, (e) -> editor.setRouted(routedCheck.getSelection()));
	return menu;
}
 
Example 20
Source File: AbstractTableDialogEx.java    From logbook with MIT License 4 votes vote down vote up
/**
 * Open the dialog.
 */
public void open() {
    // シェルを作成
    this.shell = new Shell(this.getParent(), this.getStyle());
    this.shell.setSize(this.getSize());
    // ウインドウ位置を復元
    LayoutLogic.applyWindowLocation(this.getClass(), this.shell);
    // 閉じた時にウインドウ位置を保存
    this.shell.addShellListener(new SaveWindowLocationAdapter(this.getClass()));

    this.shell.setText(this.getTitle());
    this.shell.setLayout(new FillLayout());
    // メニューバー
    this.menubar = new Menu(this.shell, SWT.BAR);
    this.shell.setMenuBar(this.menubar);
    // メニューバーのメニュー
    MenuItem fileroot = new MenuItem(this.menubar, SWT.CASCADE);
    fileroot.setText("ファイル");
    this.filemenu = new Menu(fileroot);
    fileroot.setMenu(this.filemenu);

    MenuItem savecsv = new MenuItem(this.filemenu, SWT.NONE);
    savecsv.setText("CSVファイルに保存(&S)\tCtrl+S");
    savecsv.setAccelerator(SWT.CTRL + 'S');
    savecsv.addSelectionListener(new TableToCsvSaveAdapter(this.shell, this.getTitle(),
            () -> this.getSelectionTable().getTable()));

    MenuItem operoot = new MenuItem(this.menubar, SWT.CASCADE);
    operoot.setText("操作");
    this.opemenu = new Menu(operoot);
    operoot.setMenu(this.opemenu);

    MenuItem reload = new MenuItem(this.opemenu, SWT.NONE);
    reload.setText("再読み込み(&R)\tF5");
    reload.setAccelerator(SWT.F5);
    reload.addSelectionListener(new TableReloadAdapter());

    Boolean isCyclicReload = AppConfig.get().getCyclicReloadMap().get(this.getClass().getName());
    MenuItem cyclicReload = new MenuItem(this.opemenu, SWT.CHECK);
    cyclicReload.setText("定期的に再読み込み(&A)\tCtrl+F5");
    cyclicReload.setAccelerator(SWT.CTRL + SWT.F5);
    if ((isCyclicReload != null) && isCyclicReload.booleanValue()) {
        cyclicReload.setSelection(true);
    }
    CyclicReloadAdapter adapter = new CyclicReloadAdapter(cyclicReload);
    cyclicReload.addSelectionListener(adapter);
    adapter.setCyclicReload(cyclicReload);

    MenuItem selectVisible = new MenuItem(this.opemenu, SWT.NONE);
    selectVisible.setText("列の表示・非表示(&V)");
    selectVisible.addSelectionListener(new SelectVisibleColumnAdapter());

    new MenuItem(this.opemenu, SWT.SEPARATOR);

    // 閉じた時に設定を保存
    this.shell.addShellListener(new ShellAdapter() {
        @Override
        public void shellClosed(ShellEvent e) {
            AppConfig.get().getCyclicReloadMap()
                    .put(AbstractTableDialogEx.this.getClass().getName(), cyclicReload.getSelection());
        }
    });

    this.createContents();
    this.shell.open();
    this.shell.layout();
    Display display = this.getParent().getDisplay();
    while (!this.shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    // タスクがある場合キャンセル
    if (this.future != null) {
        this.future.cancel(false);
    }
}