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

The following examples show how to use org.eclipse.swt.widgets.Table#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: ColumnBrowserWidget.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Create a column that displays data
 */
private void createTable() {
	final Table table = new Table(composite, SWT.SINGLE | SWT.H_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
	new TableColumn(table, SWT.LEFT);

	table.setLayoutData(new RowData(150, 175));
	columns.add(table);

	addTableListeners(table);

	if (super.getBackground() != null && super.getBackground().getRed() != 240 && super.getBackground().getGreen() != 240 && super.getBackground().getBlue() != 240) {
		table.setBackground(super.getBackground());
	}
	table.setBackgroundImage(super.getBackgroundImage());
	table.setBackgroundMode(super.getBackgroundMode());
	table.setCursor(super.getCursor());
	table.setFont(super.getFont());
	table.setForeground(super.getForeground());
	table.setMenu(super.getMenu());
	table.setToolTipText(super.getToolTipText());

}
 
Example 2
Source File: FilteredItemsSelectionDialog.java    From tlaplus with MIT License 6 votes vote down vote up
private void createPopupMenu() {
	removeHistoryItemAction = new RemoveHistoryItemAction();
	removeHistoryActionContributionItem = new ActionContributionItem(
			removeHistoryItemAction);

	contextMenuManager = new MenuManager();
	contextMenuManager.setRemoveAllWhenShown(true);
	contextMenuManager.addMenuListener(new IMenuListener() {
		
		public void menuAboutToShow(IMenuManager manager) {
			fillContextMenu(manager);
		}
	});

	final Table table = list.getTable();
	Menu menu= contextMenuManager.createContextMenu(table);
	table.setMenu(menu);
}
 
Example 3
Source File: AbstractTableDialogEx.java    From logbook with MIT License 6 votes vote down vote up
/**
 * テーブルを追加します
 *
 * @param parent テーブルの親コンポジット
 * @return TableWrapper
 */
protected TableWrapper<T> addTable(Composite parent) {
    // テーブル
    Table table = new Table(parent, SWT.FULL_SELECTION | SWT.MULTI);
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    table.addKeyListener(new TableKeyShortcutAdapter(table));

    // テーブル右クリックメニュー
    Menu tablemenu = new Menu(table);
    table.setMenu(tablemenu);
    MenuItem sendclipbord = new MenuItem(tablemenu, SWT.NONE);
    sendclipbord.addSelectionListener(new TableToClipboardAdapter(table));
    sendclipbord.setText("クリップボードにコピー(&C)");
    MenuItem reloadtable = new MenuItem(tablemenu, SWT.NONE);
    reloadtable.setText("再読み込み(&R)");
    reloadtable.addSelectionListener(new TableReloadAdapter());

    TableWrapper<T> wrapper = new TableWrapper<T>(table, this.clazz)
            .setDialogClass(this.getClass())
            .setDecorator(TableItemDecorator.stripe(SWTResourceManager.getColor(AppConstants.ROW_BACKGROUND)));
    this.tables.add(wrapper);
    return wrapper;
}
 
Example 4
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 table viewer.
 */
public static void bind(TableViewer viewer, Action... actions) {
	Table table = viewer.getTable();
	if (table == null)
		return;
	MenuManager menu = new MenuManager();
	for (Action action : actions)
		menu.add(action);
	table.setMenu(menu.createContextMenu(table));
}
 
Example 5
Source File: FilterTableControl.java    From depan with Apache License 2.0 4 votes vote down vote up
public void createContextMenu(MenuManager mgr) {
  Table filterTable = filterViewer.getTable();
  Menu menu = mgr.createContextMenu(filterTable);
  filterTable.setMenu(menu);
}
 
Example 6
Source File: ProjectNaturesPage.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected Control createContents(Composite parent)
{
	Composite composite = new Composite(parent, SWT.NONE);
	composite.setLayout(new GridLayout());
	composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

	fProject = (IProject) getElement().getAdapter(IResource.class);
	try
	{
		if (fProject.isOpen())
		{
			// Can only access decription if project exists and is open...
			fCurrentProjectNatures = fProject.getDescription().getNatureIds();
		}
		else
		{
			fCurrentProjectNatures = new String[0];
		}
	}
	catch (CoreException e)
	{
		IdeLog.logError(UIEplPlugin.getDefault(), EplMessages.ProjectNaturesPage_ERR_RetrieveNatures, e);
		fCurrentProjectNatures = new String[0];
	}
	fLabelProvider = new NaturesLabelProvider(fNatureDescriptions);

	// assumes the first one in the array is the primary nature
	fInitialPrimaryNature = fCurrentProjectNatures.length == 0 ? null : fCurrentProjectNatures[0];
	updatePrimaryNature(fInitialPrimaryNature);

	setDescription(MessageFormat.format(EplMessages.ProjectNaturesPage_Description, fProject.getName()));
	Label description = createDescriptionLabel(composite);
	description.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

	Composite tableComposite = new Composite(composite, SWT.NONE);
	tableComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).create());
	tableComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

	fTableViewer = CheckboxTableViewer.newCheckList(tableComposite, SWT.TOP | SWT.BORDER);
	Table table = fTableViewer.getTable();
	table.setLinesVisible(true);
	table.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

	TableColumn column = new TableColumn(table, SWT.LEFT);
	column.setWidth(350);

	fTableViewer.setContentProvider(getContentProvider());
	fTableViewer.setLabelProvider(getLabelProvider());
	fTableViewer.setComparator(getViewerComperator());
	fTableViewer.setInput(fProject.getWorkspace());
	if (!fProject.isAccessible())
	{
		fTableViewer.getControl().setEnabled(false);
	}
	fTableViewer.setCheckedElements(fCurrentProjectNatures);
	fTableViewer.addCheckStateListener(this);
	fTableViewer.addSelectionChangedListener(new ISelectionChangedListener()
	{
		public void selectionChanged(SelectionChangedEvent event)
		{
			updateButtons();
		}
	});
	fInitialCheckedItems = fTableViewer.getCheckedElements();
	table.setMenu(createMenu(table));

	// Add the buttons
	Composite buttons = new Composite(tableComposite, SWT.NONE);
	buttons.setLayout(GridLayoutFactory.fillDefaults().create());
	buttons.setLayoutData(GridDataFactory.fillDefaults().grab(false, true).create());
	fMakePrimaryButton = createButton(EplMessages.ProjectNaturesPage_LBL_MakePrimary, buttons);
	updateButtons();

	noDefaultAndApplyButton();

	return composite;
}
 
Example 7
Source File: WizardFolderImportPage.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
 */
public void createControl(Composite parent)
{
	// Collect the existing project names to avoid conflicts.
	IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
	projectsNames = new HashSet<String>();
	for (IProject project : projects)
	{
		projectsNames.add(project.getName());
	}
	modifyListener = new InputModifyListener();
	initializeDialogUnits(parent);

	Composite workArea = new Composite(parent, SWT.NONE);
	setControl(workArea);

	workArea.setLayout(new GridLayout());
	workArea.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));

	createProjectsRoot(workArea);

	Dialog.applyDialogFont(workArea);
	fLabelProvider = new NaturesLabelProvider(fNatureDescriptions);

	Label l = new Label(workArea, SWT.NONE);
	l.setText(EplMessages.WizardFolderImportPage_project_type_title);

	natureContributors = PrimaryNaturesManager.getManager().getContributorsMap();

	Composite tableComposite = new Composite(workArea, SWT.NONE);
	tableComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).create());
	tableComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

	// Table for project natures
	fTableViewer = CheckboxTableViewer.newCheckList(tableComposite, SWT.TOP | SWT.BORDER);
	Table table = fTableViewer.getTable();
	table.setLinesVisible(true);
	table.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

	TableColumn column = new TableColumn(table, SWT.LEFT);
	column.setWidth(350);

	fTableViewer.setContentProvider(getContentProvider());
	fTableViewer.setLabelProvider(getLabelProvider());
	fTableViewer.setComparator(getViewerComperator());
	fTableViewer.setInput(ResourcesPlugin.getWorkspace());
	fTableViewer.addCheckStateListener(this);
	fTableViewer.addSelectionChangedListener(new ISelectionChangedListener()
	{
		public void selectionChanged(SelectionChangedEvent event)
		{
			updateButtons();
		}
	});
	table.setMenu(createMenu(table));

	// Add the buttons
	Composite buttons = new Composite(tableComposite, SWT.NONE);
	buttons.setLayout(GridLayoutFactory.fillDefaults().create());
	buttons.setLayoutData(GridDataFactory.fillDefaults().grab(false, true).create());
	fMakePrimaryButton = createButton(EplMessages.WizardFolderImportPage_make_primary_label, buttons);
	updateButtons();

	setPageComplete(false);
	setPrimaryNatureFromContributions(null);
	fTableViewer.setCheckedElements(new String[] { fPrimaryNature });

	if (!StringUtil.isEmpty(directoryPath))
	{
		directoryPathField.setText(directoryPath);
		setProjectName();
		setPageComplete(true);
	}
}
 
Example 8
Source File: LegendTable.java    From dawnsci with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @param parent
 * @param style
 */
public LegendTable(Composite parent, int style) {
	
	super(parent, style);
	this.setLayout(new GridLayout(1, false));
	editors = new LinkedList<TableEditor>();
	buttons = new LinkedList<Button>();
	tblLegend = new Table(this, SWT.DOUBLE_BUFFERED );
	tblLegend.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
	tblLegend.setHeaderVisible(false);
	tblLegend.setLinesVisible(true);
	tblLegend.setEnabled(true);
	tblLegend.addKeyListener(this);
	{
		TableColumn tblclmnColour = new TableColumn(tblLegend, SWT.NONE);
		tblclmnColour.setWidth(82);
		tblclmnColour.setResizable(false);
		tblclmnColour.setText("Colour");
	}
	{
		TableColumn tblclmnDescription = new TableColumn(tblLegend, SWT.NONE);
		tblclmnDescription.setWidth(250);
		tblclmnDescription.setResizable(true);
		tblclmnDescription.setText("Description");
	}
	if (isRequireActiveButton()) {
		TableColumn tblclmnVisible = new TableColumn(tblLegend, SWT.NONE);
		tblclmnVisible.setWidth(80);
		tblclmnVisible.setResizable(false);
		tblclmnVisible.setText("Visible");
	}
	// The headers have to be visible to resize the column. Sometimes people
	// use long dataset names, therefore need to resize the legend to see
	// what's plotted. We add a right click action to the table to show headers
	// which then allow it to be resized. There may be an easier way to do this.
	final MenuManager man = new MenuManager();
	man.add(new Action("Resizable", IAction.AS_CHECK_BOX) {
		private boolean show = false;
		 @Override
		public void run() {
			show = !show;
			tblLegend.setHeaderVisible(show);
		}
	});
	final Menu menu = man.createContextMenu(tblLegend);
	tblLegend.setMenu(menu);
}
 
Example 9
Source File: UsageSettings.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
public void addContextMenuSupport(TableViewer tableViewer, MenuManager menuManager){
	Table table = tableViewer.getTable();
	Menu menu = menuManager.createContextMenu(table);
	table.setMenu(menu);
}
 
Example 10
Source File: ColumnBrowserWidget.java    From nebula with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Sets the receiver's pop up menu to the argument. All controls may optionally
 * have a pop up menu that is displayed when the user requests one for the
 * control. The sequence of key strokes, button presses and/or button releases
 * that are used to request a pop up menu is platform specific.
 * <p>
 * Note: Disposing of a control that has a pop up menu will dispose of the menu.
 * To avoid this behavior, set the menu to null before the control is disposed.
 * </p>
 *
 * @param menu the new pop up menu
 *
 * @exception IllegalArgumentException
 *                <ul>
 *                <li>ERROR_MENU_NOT_POP_UP - the menu is not a pop up menu</li>
 *                <li>ERROR_INVALID_PARENT - if the menu is not in the same
 *                widget tree</li>
 *                <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed
 *                </li>
 *                </ul>
 * @exception SWTException
 *                <ul>
 *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been
 *                disposed</li>
 *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
 *                thread that created the receiver</li>
 *                </ul>
 * @see org.eclipse.swt.widgets.Control#setMenu(org.eclipse.swt.widgets.Menu)
 */
@Override
public void setMenu(final Menu menu) {
	super.setMenu(menu);
	for (final Table column : columns) {
		column.setMenu(menu);
	}
}