LRESULT wmCommandChild(long /*int*/ wParam, long /*int*/ lParam) { if ((style & SWT.CHECK) != 0) { setSelection(!getSelection()); } else { if ((style & SWT.RADIO) != 0) { if ((parent.getStyle() & SWT.NO_RADIO_GROUP) != 0) { setSelection(!getSelection()); } else { selectRadio(); } } } sendSelectionEvent(SWT.Selection); return null; }
public Object createWidget(final MUIElement element, Object parent) { if (!(element instanceof MHandledMenuItem) || !(parent instanceof Menu)) return null; MHandledMenuItem itemModel = (MHandledMenuItem) element; if (itemModel.getVisibleWhen() != null) { processVisible(itemModel); } if (!itemModel.isVisible()) { return null; } // determine the index at which we should create the new item int addIndex = calcVisibleIndex(element); // OK, it's a real menu item, what kind? int flags = 0; if (itemModel.getType() == ItemType.PUSH) flags = SWT.PUSH; else if (itemModel.getType() == ItemType.CHECK) flags = SWT.CHECK; else if (itemModel.getType() == ItemType.RADIO) flags = SWT.RADIO; ParameterizedCommand cmd = itemModel.getWbCommand(); if (cmd == null) { IEclipseContext lclContext = getContext(itemModel); cmd = generateParameterizedCommand(itemModel, lclContext); } MenuItem newItem = new MenuItem((Menu) parent, flags, addIndex); setItemText(itemModel, newItem); setEnabled(itemModel, newItem); newItem.setImage(getImage(itemModel)); newItem.setSelection(itemModel.isSelected()); return newItem; }
private void updateMenuItem() { final MenuItem item = (MenuItem) this.widget; final boolean shouldBeEnabled = isEnabled(); // disabled command + visibility follows enablement == disposed if (item.isDisposed()) { return; } String text = this.label; text = updateMnemonic(text); final String keyBindingText = null; if (text != null) { if (keyBindingText == null) { item.setText(text); } else { item.setText(text + '\t' + keyBindingText); } } if (item.getSelection() != this.checkedState) { item.setSelection(this.checkedState); } if (item.getEnabled() != shouldBeEnabled) { item.setEnabled(shouldBeEnabled); } }
/** * Recursive method to create a menu from the contribute items of a manger * * @param menu actual menu * @param items manager contributor items */ private void createMenu(Menu menu, IContributionItem[] items) { for (IContributionItem item : items) { if (item instanceof MenuManager) { MenuManager manager = (MenuManager) item; MenuItem subMenuItem = new MenuItem(menu, SWT.CASCADE); subMenuItem.setText(manager.getMenuText()); Menu subMenu = new Menu(Display.getCurrent().getActiveShell(), SWT.DROP_DOWN); subMenuItem.setMenu(subMenu); createMenu(subMenu, manager.getItems()); } else if (item instanceof ActionContributionItem) { ActionContributionItem actionItem = (ActionContributionItem) item; if (actionItem.getAction() instanceof CustomSelectionAction) { final CustomSelectionAction action = (CustomSelectionAction) actionItem.getAction(); MenuItem actionEnrty = new MenuItem(menu, SWT.CHECK); action.setSelection(getLastRawSelection()); actionEnrty.setText(actionItem.getAction().getText()); actionEnrty.setSelection(action.isChecked()); actionEnrty.setEnabled(action.canExecute()); actionEnrty.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { action.run(); } }); } } } }
/** * Creates the menu item for the editor descriptor. * * @param menu the menu to add the item to * @param descriptor the editor descriptor, or null for the system editor * @param preferredEditor the descriptor of the preferred editor, or <code>null</code> */ private MenuItem createMenuItem( Menu menu, final IEditorDescriptor descriptor, final IEditorDescriptor preferredEditor) { // XXX: Would be better to use bold here, but SWT does not support it. final MenuItem menuItem = new MenuItem(menu, SWT.RADIO); boolean isPreferred = preferredEditor != null && descriptor.getId().equals(preferredEditor.getId()); menuItem.setSelection(isPreferred); menuItem.setText(descriptor.getLabel()); Image image = getImage(descriptor); if (image != null) { menuItem.setImage(image); } Listener listener = new Listener() { public void handleEvent(Event event) { switch (event.type) { case SWT.Selection: if (menuItem.getSelection()) { openEditor(descriptor, false); } break; } } }; menuItem.addListener(SWT.Selection, listener); return menuItem; }
boolean setRadioSelection(boolean value) { if ((style & SWT.RADIO) == 0) return false; if (getSelection() != value) { setSelection(value); sendSelectionEvent(SWT.Selection); } return true; }
void selectRadio() { int index = 0; MenuItem[] items = parent.getItems(); while (index < items.length && items[index] != this) index++; int i = index - 1; while (i >= 0 && items[i].setRadioSelection(false)) --i; int j = index + 1; while (j < items.length && items[j].setRadioSelection(false)) j++; setSelection(true); }
/** * Create the options menu. * * @param header the header from which the menu hangs */ private void createOptionsMenu(final MenuItem header) { if (optionsMenu != null) { optionsMenu.dispose(); } optionsMenu = new Menu(shell, SWT.DROP_DOWN); MenuItem viewShowPathItem = new MenuItem(optionsMenu, SWT.CHECK); viewShowPathItem.setText("&Show agent's path\tCTRL+P"); viewShowPathItem.setAccelerator(SWT.CTRL + 'P'); viewShowPathItem.setSelection(true); viewShowPathItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { gui.setPathShown(!gui.isPathShown()); } }); MenuItem simulateNightItem = new MenuItem(optionsMenu, SWT.CHECK); simulateNightItem.setText("Simulate &night"); simulateNightItem.setSelection(gui.isNightSimulated()); simulateNightItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { gui.simulateNight(((MenuItem) e.getSource()).getSelection()); } }); new MenuItem(optionsMenu, SWT.SEPARATOR); MenuItem toolsOptionsItem = new MenuItem(optionsMenu, SWT.PUSH); toolsOptionsItem.setText("Con&figuration\tCtrl+T"); toolsOptionsItem.setAccelerator(SWT.CTRL + 'T'); toolsOptionsItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { new ConfigShell(siafuConfig); } }); optionsMenuHeader.setMenu(optionsMenu); }
/** * Creates menu * * @param parent parent control * @param strings collection of strings * @param selectedString selected item * @param defaultString default item if any or null * @return Menu */ protected Menu createMenu( String[] strings, String selectedString, String defaultString, boolean bDefault) { if (strings == null || strings.length == 0) return null; Menu menu = new Menu(this.control); // insert default value first if (defaultString != null) { MenuItem menuItem = new MenuItem(menu, SWT.RADIO); menuItem.setText(defaultString); menuItem.setSelection(bDefault); menuItem = new MenuItem(menu, SWT.SEPARATOR); } for (String s : strings) { MenuItem menuItem = new MenuItem(menu, SWT.RADIO); menuItem.setText(s); menuItem.setSelection(!bDefault && s.equals(selectedString)); } return menu; }
private void setChecked(boolean checked) { if (checkedState == checked) { return; } checkedState = checked; if (widget instanceof MenuItem) { ((MenuItem) widget).setSelection(checkedState); } else if (widget instanceof ToolItem) { ((ToolItem) widget).setSelection(checkedState); } }
public void addOperationFilter(final Filter filter) { MenuItem[] items = filtersMenu.getItems(); int pos = 0; for (MenuItem item : items) { if (item == configureItem) { break; } pos++; } pos--; operationFilters.add(filter); final MenuItem item = new MenuItem(filtersMenu, SWT.CHECK, pos); item.setText(filter.getName()); item.setSelection(filter.getEnabled()); item.setData(filter); item.addSelectionListener(this); }
private Menu createOptionsMenu(Shell shell) { final Menu menu = new Menu(shell, SWT.POP_UP); final MenuItem displayImagesItem = new MenuItem(menu, SWT.CHECK); displayImagesItem.setText("Display Images"); displayImagesItem.setSelection(displayImages); final MenuItem imagesAsHexItem = new MenuItem(menu, SWT.CHECK); imagesAsHexItem.setText("Display Images with Hex Viewer"); final MenuItem decodeItem = new MenuItem(menu, SWT.CHECK); decodeItem.setText("Remove URL encoding"); displayImagesItem.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { boolean value = displayImagesItem.getSelection(); imagesAsHexItem.setEnabled(value); setDisplayImageState(value); displayImages = value; } }); imagesAsHexItem.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { boolean value = imagesAsHexItem.getSelection(); setDisplayImagesAsHexState(value); displayImagesAsHex = value; } }); decodeItem.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { boolean value = decodeItem.getSelection(); setUrlDecodeState(value); urlDecodeState = value; } }); return menu; }
public Menu getMenu(Control parent) { if (menu != null) { menu.dispose(); } menu = new Menu(parent); Collection<String> availableItems = getAvailableItems(); for (final String menuItemId : availableItems) { MenuItem menuItem = new MenuItem(menu, getMenuStyle()); menuItem.setText(getDisplayName(menuItemId)); menuItem.setSelection(getSelection(menuItemId)); menuItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { handleSelection(menuItemId); } }); } return menu; }
public void createDefaultMenuItem(Menu menu, final IFileRevision revision) { final MenuItem menuItem = new MenuItem(menu, SWT.RADIO); menuItem.setSelection(Utils.getDefaultEditor(revision) == null); menuItem.setText(TeamUIMessages.LocalHistoryPage_OpenWithMenu_DefaultEditorDescription); Listener listener = new Listener() { public void handleEvent(Event event) { switch (event.type) { case SWT.Selection: if (menuItem.getSelection()) { openEditor(Utils.getDefaultEditor(revision), false); } break; } } }; menuItem.addListener(SWT.Selection, listener); }
private void addShowTextItem(final Menu menu) { final MenuItem showtextMenuItem = new MenuItem(menu, SWT.CHECK); showtextMenuItem.setText(WorkbenchMessages.PerspectiveBar_showText); showtextMenuItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { boolean preference = showtextMenuItem.getSelection(); if (preference != PrefUtil.getAPIPreferenceStore() .getDefaultBoolean( IWorkbenchPreferenceConstants.SHOW_TEXT_ON_PERSPECTIVE_BAR)) { PrefUtil.getInternalPreferenceStore() .setValue(IPreferenceConstants.OVERRIDE_PRESENTATION, true); } PrefUtil.getAPIPreferenceStore() .setValue(IWorkbenchPreferenceConstants.SHOW_TEXT_ON_PERSPECTIVE_BAR, preference); changeShowText(preference); } }); showtextMenuItem.setSelection( PrefUtil.getAPIPreferenceStore() .getBoolean(IWorkbenchPreferenceConstants.SHOW_TEXT_ON_PERSPECTIVE_BAR)); }
/** * @param parent * @param repository * @param pathList */ public NonDeletedFilesTree(Composite parent, Repository repository, List<String> pathList) { super(createComposite(parent), SWT.BORDER); this.filePaths = pathList; Composite main = getTree().getParent(); GridDataFactory.fillDefaults().grab(true, true).applyTo(getTree()); final FileTreeContentProvider cp = new FileTreeContentProvider(repository); setContentProvider(cp); setLabelProvider(new FileTreeLabelProvider()); setInput(this.filePaths); expandAll(); final ToolBar dropDownBar = new ToolBar(main, SWT.FLAT | SWT.RIGHT); GridDataFactory.swtDefaults() .align(SWT.BEGINNING, SWT.BEGINNING) .grab(false, false) .applyTo(dropDownBar); final ToolItem dropDownItem = new ToolItem(dropDownBar, SWT.DROP_DOWN); Image dropDownImage = UIIcons.HIERARCHY.createImage(); UIUtils.hookDisposal(dropDownItem, dropDownImage); dropDownItem.setImage(dropDownImage); final Menu menu = new Menu(dropDownBar); dropDownItem.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent e) { menu.dispose(); } }); dropDownItem.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Rectangle b = dropDownItem.getBounds(); Point p = dropDownItem.getParent().toDisplay(new Point(b.x, b.y + b.height)); menu.setLocation(p.x, p.y); menu.setVisible(true); } }); final MenuItem showRepoRelative = new MenuItem(menu, SWT.RADIO); showRepoRelative.setText(UIText.NonDeletedFilesTree_RepoRelativePathsButton); showRepoRelative.setSelection(true); showRepoRelative.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (showRepoRelative.getSelection()) { cp.setMode(Mode.REPO_RELATIVE_PATHS); setInput(getInput()); expandAll(); } } }); final MenuItem showFull = new MenuItem(menu, SWT.RADIO); showFull.setText(UIText.NonDeletedFilesTree_FileSystemPathsButton); showFull.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (showFull.getSelection()) { cp.setMode(Mode.FULL_PATHS); setInput(getInput()); expandAll(); } } }); final MenuItem showResource = new MenuItem(menu, SWT.RADIO); showResource.setText(UIText.NonDeletedFilesTree_ResourcePathsButton); showResource.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (showResource.getSelection()) { cp.setMode(Mode.RESOURCE_PATHS); setInput(getInput()); expandAll(); } } }); }
private void fillMenu(final Menu m) { if (history.size() > 0) { TestResultLP lp = new TestResultLP(); for (int a = history.size() - 1; a >= 0; a--) { final TestSuite ts = history.get(a); MenuItem mi = new MenuItem(m, SWT.RADIO); mi.setText(lp.getText(ts)); mi.setImage(lp.getImage(ts)); if (historyIndex != a) { final int idx = a; mi.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { historyIndex = idx; setInput(ts, false); } }); } else { mi.setSelection(true); } } new MenuItem(m, SWT.SEPARATOR); /** clear all terminated * */ MenuItem mi = new MenuItem(m, SWT.PUSH); mi.setText(UITexts.test_history_clear); mi.setImage(HaskellUIImages.getImage(IImageNames.REMOVE_ALL)); mi.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { int a = 0; for (Iterator<TestSuite> it = history.iterator(); it.hasNext(); ) { final TestSuite ts = it.next(); /** terminated= !PENDING * */ if (ts.getRoot().isFinished()) { it.remove(); /** history index moves too * */ if (historyIndex >= a) { historyIndex--; } } } /** defensive * */ if (historyIndex < 0) { historyIndex = history.size() - 1; } if (historyIndex >= 0) { setInput(history.get(historyIndex), false); } else { clear(); /** remove * */ } } }); } else { /** nothing to show * */ MenuItem mi = new MenuItem(m, SWT.PUSH); mi.setText(UITexts.test_history_none); mi.setEnabled(false); } }
public SpinStatusComposite( Composite parent, int style, final Display display, String label, ISpin spin) { super(parent, style); GridDataFactory.fillDefaults().applyTo(this); GridLayoutFactory.swtDefaults().numColumns(1).applyTo(this); Group grp = new Group(this, style); GridDataFactory.fillDefaults().applyTo(grp); GridLayoutFactory.swtDefaults().numColumns(1).applyTo(grp); grp.setText(label); this.display = display; GridLayoutFactory.swtDefaults().numColumns(1).applyTo(this); GridDataFactory.fillDefaults().applyTo(this); this.spin = spin; currentColor = SPIN_OFF_COLOR; try { if (spin.getState().equalsIgnoreCase("enabled")) { currentColor = SPIN_ON_COLOR; } else { currentColor = SPIN_OFF_COLOR; } } catch (DeviceException e1) { logger.error("Failed to get spin status", e1); } canvas = new Canvas(grp, SWT.NONE); GridData gridData = new GridData(GridData.VERTICAL_ALIGN_FILL); gridData.widthHint = 40; gridData.heightHint = 40; canvas.setLayoutData(gridData); canvas.addPaintListener( new PaintListener() { @Override public void paintControl(PaintEvent e) { GC gc = e.gc; gc.setAntialias(SWT.ON); gc.setBackground(currentColor); gc.setLineWidth(1); Rectangle clientArea = canvas.getClientArea(); final int margin = 4; final Point topLeft = new Point(margin, margin); final Point size = new Point(clientArea.width - margin * 2, clientArea.height - margin * 2); gc.fillOval(topLeft.x, topLeft.y, size.x, size.y); gc.drawOval(topLeft.x, topLeft.y, size.x, size.y); } }); canvas.setMenu(createPopup(this)); // initialize tooltip try { if (spin.getState().equalsIgnoreCase("enabled")) { canvas.setToolTipText(SPIN_ON_TOOL_TIP); spinOn.setSelection(true); } else { canvas.setToolTipText(SPIN_OFF_TOOL_TIP); spinOff.setSelection(true); } } catch (DeviceException e1) { logger.error("Failed to get spin status", e1); } final IObserver spinObserver = new IObserver() { @Override public void update(final Object theObserved, final Object changeCode) { Display.getDefault() .asyncExec( new Runnable() { @Override public void run() { String value = ""; if (theObserved instanceof ISpin) { if (changeCode instanceof String) { value = ((String) changeCode); if (value.equalsIgnoreCase("Enabled")) { currentColor = SPIN_ON_COLOR; canvas.setToolTipText(SPIN_ON_TOOL_TIP); spinOn.setSelection(true); } else { currentColor = SPIN_OFF_COLOR; canvas.setToolTipText(SPIN_OFF_TOOL_TIP); spinOff.setSelection(true); } } } updateBatonCanvas(); } }); } }; spin.addIObserver(spinObserver); }
/* * (non-Javadoc) * * @see org.eclipse.jface.action.ContributionItem#update(java.lang.String) */ public void update(String id) { if (widget != null) { if (widget instanceof MenuItem) { MenuItem item = (MenuItem) widget; String text = label; if (text == null) { if (command != null) { try { text = command.getCommand().getName(); } catch (NotDefinedException e) { WorkbenchPlugin.log( "Update item failed " //$NON-NLS-1$ + getId(), e); } } } // TODO: [bm] key bindings // text = updateMnemonic(text); // // String keyBindingText = null; // if (command != null) { // TriggerSequence[] bindings = bindingService // .getActiveBindingsFor(command); // if (bindings.length > 0) { // keyBindingText = bindings[0].format(); // } // } // if (text != null) { // if (keyBindingText == null) { item.setText(text); // } else { // item.setText(text + '\t' + keyBindingText); // } // } updateIcons(); if (item.getSelection() != checkedState) { item.setSelection(checkedState); } boolean shouldBeEnabled = isEnabled(); if (item.getEnabled() != shouldBeEnabled) { item.setEnabled(shouldBeEnabled); } } else if (widget instanceof ToolItem) { ToolItem item = (ToolItem) widget; if (icon != null) { updateIcons(); } else if (label != null) { item.setText(label); } if (tooltip != null) item.setToolTipText(tooltip); else { String text = label; if (text == null) { if (command != null) { try { text = command.getCommand().getName(); } catch (NotDefinedException e) { WorkbenchPlugin.log( "Update item failed " //$NON-NLS-1$ + getId(), e); } } } if (text != null) { item.setToolTipText(text); } } if (item.getSelection() != checkedState) { item.setSelection(checkedState); } boolean shouldBeEnabled = isEnabled(); if (item.getEnabled() != shouldBeEnabled) { item.setEnabled(shouldBeEnabled); } } } }
void initWidgets() { GlobalConfWinLab = new Label(MainShell, SWT.NORMAL | SWT.CENTER); GlobalUsersGroup = new Group(MainShell, SWT.NONE); GlobalOutWin = new Text(MainShell, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL); GlobalUsersList = new List(GlobalUsersGroup, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); GlobalInpWinLab = new Label(MainShell, SWT.NORMAL | SWT.CENTER); GlobalInpWin = new Text(MainShell, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL); GlobalSendBut = new Button(MainShell, SWT.PUSH); GlobalClearBut = new Button(MainShell, SWT.PUSH); GlobalMainMenu = new Menu(MainShell, SWT.BAR); GlobalOptionsMenu = new Menu(MainShell, SWT.DROP_DOWN); GlobalSettingsMenu = new Menu(MainShell, SWT.DROP_DOWN); GlobalProfileMenu = new Menu(MainShell, SWT.DROP_DOWN); GlobalProfileItem = new MenuItem(GlobalSettingsMenu, SWT.CASCADE); GlobalOptionsItem = new MenuItem(GlobalMainMenu, SWT.CASCADE); GlobalOptionsItem.setMenu(GlobalOptionsMenu); GlobalSettingsItem = new MenuItem(GlobalMainMenu, SWT.CASCADE); GlobalSettingsItem.setMenu(GlobalSettingsMenu); GlobalProfileItem.setMenu(GlobalProfileMenu); GlobalExitItem = new MenuItem(GlobalOptionsMenu, SWT.CASCADE); GlobalConnectionItem = new MenuItem(GlobalSettingsMenu, SWT.CASCADE); GlobalUserNameItem = new MenuItem(GlobalSettingsMenu, SWT.CASCADE); GlobalAboutItem = new MenuItem(GlobalMainMenu, SWT.CASCADE); GlobalServerItem = new MenuItem(GlobalProfileMenu, SWT.RADIO); GlobalClientItem = new MenuItem(GlobalProfileMenu, SWT.RADIO); GlobalConfWinLab.setText("Conference window:"); GlobalOutWin.setText(""); GlobalInpWinLab.setText("Input Window:"); GlobalInpWin.setText(""); GlobalSendBut.setText("Send"); GlobalClearBut.setText("Clear"); GlobalOptionsItem.setText("Options"); GlobalSettingsItem.setText("Settings"); GlobalProfileItem.setText("Profile"); GlobalExitItem.setText("Exit"); GlobalConnectionItem.setText("Connection"); GlobalUserNameItem.setText("User"); GlobalAboutItem.setText("About"); GlobalServerItem.setText("Server"); GlobalClientItem.setText("Client"); GlobalUsersGroup.setText("Online Users"); GlobalOutWin.setFont(Calibri); GlobalInpWin.setFont(Calibri); GlobalSendBut.setFont(Calibri); GlobalClearBut.setFont(Calibri); GlobalUsersGroup.setFont(Calibri); GlobalUsersList.setFont(Calibri); GlobalConfWinLab.setFont(Calibri); GlobalInpWinLab.setFont(Calibri); GlobalOutWin.setBackground(White); GlobalInpWin.setBackground(White); GlobalConfWinLab.setLayoutData( new GridData(SWT.CENTER | SWT.FILL, SWT.CENTER | SWT.FILL, true, true, 2, 1)); GlobalOutWin.setLayoutData( new GridData(SWT.CENTER | SWT.FILL, SWT.CENTER | SWT.FILL, true, true, 2, 1)); ((GridData) GlobalOutWin.getLayoutData()).widthHint = 300; ((GridData) GlobalOutWin.getLayoutData()).heightHint = 200; GlobalInpWinLab.setLayoutData( new GridData(SWT.CENTER | SWT.FILL, SWT.CENTER | SWT.FILL, true, true, 2, 1)); GlobalInpWin.setLayoutData( new GridData(SWT.CENTER | SWT.FILL, SWT.CENTER | SWT.FILL, true, true, 1, 2)); ((GridData) GlobalInpWin.getLayoutData()).widthHint = 250; ((GridData) GlobalInpWin.getLayoutData()).heightHint = 100; GlobalSendBut.setLayoutData( new GridData(SWT.CENTER | SWT.FILL, SWT.CENTER | SWT.FILL, true, true, 1, 1)); ((GridData) GlobalSendBut.getLayoutData()).widthHint = 50; ((GridData) GlobalSendBut.getLayoutData()).heightHint = 30; GlobalClearBut.setLayoutData( new GridData(SWT.CENTER | SWT.FILL, SWT.CENTER | SWT.FILL, true, true, 1, 1)); ((GridData) GlobalClearBut.getLayoutData()).widthHint = 50; ((GridData) GlobalClearBut.getLayoutData()).heightHint = 30; GlobalUsersGroup.setLayoutData(new GridData(SWT.CENTER | SWT.FILL, SWT.FILL, true, true, 1, 5)); ((GridData) GlobalUsersGroup.getLayoutData()).widthHint = 150; ((GridData) GlobalUsersGroup.getLayoutData()).heightHint = 300; GlobalUsersGroup.setLayout(new GridLayout(2, false)); GlobalUsersList.setLayoutData(new GridData(GridData.FILL_BOTH)); ((GridData) GlobalUsersList.getLayoutData()).widthHint = 150; ((GridData) GlobalUsersList.getLayoutData()).heightHint = 300; GlobalOutWin.setEditable(false); GlobalInpWin.setFocus(); if (UserProfile == JTC.SERVER) GlobalServerItem.setSelection(true); else GlobalClientItem.setSelection(true); }
/** 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); // テーブルより前に作成する必要があるコンポジットを作成 this.createContentsBefore(); // テーブル this.table = new Table(this.getTableParent(), SWT.FULL_SELECTION | SWT.MULTI); this.table.addKeyListener(new TableKeyShortcutAdapter(this.header, this.table)); this.table.setLinesVisible(true); this.table.setHeaderVisible(true); // メニューバーのメニュー 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.getTableHeader(), this.table)); 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.tablemenu = new Menu(this.table); this.table.setMenu(this.tablemenu); MenuItem sendclipbord = new MenuItem(this.tablemenu, SWT.NONE); sendclipbord.addSelectionListener(new TableToClipboardAdapter(this.header, this.table)); sendclipbord.setText("クリップボードにコピー(&C)"); MenuItem reloadtable = new MenuItem(this.tablemenu, SWT.NONE); reloadtable.setText("再読み込み(&R)"); reloadtable.addSelectionListener(new TableReloadAdapter()); // テーブルにヘッダーをセット this.setTableHeader(); // テーブルに内容をセット this.updateTableBody(); this.setTableBody(); // 列幅を整える this.packTableHeader(); // 閉じた時に設定を保存 this.shell.addShellListener( new ShellAdapter() { @Override public void shellClosed(ShellEvent e) { AppConfig.get() .getCyclicReloadMap() .put(AbstractTableDialog.this.getClass().getName(), cyclicReload.getSelection()); } }); this.createContents(); this.shell.open(); this.shell.layout(); this.display = this.getParent().getDisplay(); while (!this.shell.isDisposed()) { if (!this.display.readAndDispatch()) { this.display.sleep(); } } // タスクがある場合キャンセル if (this.future != null) { this.future.cancel(false); } }
static void show(final ConfigurationChooser chooser, ToolItem combo) { Configuration configuration = chooser.getConfiguration(); Device current = configuration.getDevice(); Menu menu = new Menu(chooser.getShell(), SWT.POP_UP); List<Device> deviceList = chooser.getDeviceList(); Sdk sdk = Sdk.getCurrent(); if (sdk != null) { AvdManager avdManager = sdk.getAvdManager(); if (avdManager != null) { boolean separatorNeeded = false; AvdInfo[] avds = avdManager.getValidAvds(); for (AvdInfo avd : avds) { for (Device device : deviceList) { if (device.getManufacturer().equals(avd.getDeviceManufacturer()) && device.getName().equals(avd.getDeviceName())) { separatorNeeded = true; MenuItem item = new MenuItem(menu, SWT.CHECK); item.setText(avd.getName()); item.setSelection(current == device); item.addSelectionListener(new DeviceMenuListener(chooser, device)); } } } if (separatorNeeded) { @SuppressWarnings("unused") MenuItem separator = new MenuItem(menu, SWT.SEPARATOR); } } } // Group the devices by manufacturer, then put them in the menu. // If we don't have anything but Nexus devices, group them together rather than // make many manufacturer submenus. boolean haveNexus = false; boolean haveNonNexus = false; if (!deviceList.isEmpty()) { Map<String, List<Device>> manufacturers = new TreeMap<String, List<Device>>(); for (Device device : deviceList) { List<Device> devices; if (isNexus(device)) { haveNexus = true; } else if (!isGeneric(device)) { haveNonNexus = true; } if (manufacturers.containsKey(device.getManufacturer())) { devices = manufacturers.get(device.getManufacturer()); } else { devices = new ArrayList<Device>(); manufacturers.put(device.getManufacturer(), devices); } devices.add(device); } if (haveNonNexus) { for (List<Device> devices : manufacturers.values()) { Menu manufacturerMenu = menu; if (manufacturers.size() > 1) { MenuItem item = new MenuItem(menu, SWT.CASCADE); item.setText(devices.get(0).getManufacturer()); manufacturerMenu = new Menu(menu); item.setMenu(manufacturerMenu); } for (final Device device : devices) { MenuItem deviceItem = new MenuItem(manufacturerMenu, SWT.CHECK); deviceItem.setText(getGenericLabel(device)); deviceItem.setSelection(current == device); deviceItem.addSelectionListener(new DeviceMenuListener(chooser, device)); } } } else { List<Device> nexus = new ArrayList<Device>(); List<Device> generic = new ArrayList<Device>(); if (haveNexus) { // Nexus for (List<Device> devices : manufacturers.values()) { for (Device device : devices) { if (isNexus(device)) { if (device.getManufacturer().equals(GENERIC)) { generic.add(device); } else { nexus.add(device); } } else { generic.add(device); } } } } if (!nexus.isEmpty()) { sortNexusList(nexus); for (final Device device : nexus) { MenuItem item = new MenuItem(menu, SWT.CHECK); item.setText(getNexusLabel(device)); item.setSelection(current == device); item.addSelectionListener(new DeviceMenuListener(chooser, device)); } @SuppressWarnings("unused") MenuItem separator = new MenuItem(menu, SWT.SEPARATOR); } // Generate the generic menu. Collections.reverse(generic); for (final Device device : generic) { MenuItem item = new MenuItem(menu, SWT.CHECK); item.setText(getGenericLabel(device)); item.setSelection(current == device); item.addSelectionListener(new DeviceMenuListener(chooser, device)); } } } @SuppressWarnings("unused") MenuItem separator = new MenuItem(menu, SWT.SEPARATOR); ConfigurationMenuListener.addTogglePreviewModeAction( menu, "Preview All Screens", chooser, RenderPreviewMode.SCREENS); Rectangle bounds = combo.getBounds(); Point location = new Point(bounds.x, bounds.y + bounds.height); location = combo.getParent().toDisplay(location); menu.setLocation(location.x, location.y); menu.setVisible(true); }