static void create(final List actions, final Composite actionBar) { Control[] children = actionBar.getChildren(); for (int i = 0; i < children.length; i++) { children[i].dispose(); } actionBar.setLayout(new RowLayout()); Iterator iterator = actions.iterator(); while (iterator.hasNext()) { Object next = iterator.next(); if (next instanceof Action) { final Action action = (Action) next; new ActionBarButton(action, actionBar); Label separator = new Label(actionBar, SWT.NONE); separator.setText(" "); Label separator2 = new Label(actionBar, SWT.NONE); separator2.setText(" "); Label separator3 = new Label(actionBar, SWT.NONE); separator3.setText(" "); } else { Label separator = new Label(actionBar, SWT.SEPARATOR | SWT.VERTICAL); separator.setForeground(Graphics.getColor(255, 255, 255)); Label separator2 = new Label(actionBar, SWT.NONE); separator2.setText(" "); Label separator3 = new Label(actionBar, SWT.NONE); separator3.setText(" "); } } actionBar.layout(); }
/** * Adds the platform to the folder on the given level. This method is recursive. If agent name is * not fitting the level, it will be added to the given composite. If it fitting for the level, * proper search will be done for sub-composite to insert the platform. * * @param folder Top composite. * @param level Wanted level. * @param platformIdent {@link PlatformIdent}. * @param agentStatusData {@link AgentStatusData}. * @param cmrRepositoryDefinition Repository agent is belonging to. */ private static void addToFolder( Composite folder, int level, PlatformIdent platformIdent, AgentStatusData agentStatusData, CmrRepositoryDefinition cmrRepositoryDefinition) { if (!accessibleForLevel(platformIdent.getAgentName(), level)) { // if name is not matching the level just add th leaf AgentLeaf agentLeaf = new AgentLeaf(platformIdent, agentStatusData, cmrRepositoryDefinition, level != 0); folder.addChild(agentLeaf); } else { // search for proper folder boolean folderExisting = false; String agentLevelName = getFolderNameFromAgent(platformIdent.getAgentName(), level); for (Component child : folder.getChildren()) { if (child instanceof Composite && ObjectUtils.equals(child.getName(), agentLevelName)) { addToFolder( (Composite) child, level + 1, platformIdent, agentStatusData, cmrRepositoryDefinition); folderExisting = true; } } // if not found create new one if (!folderExisting) { Composite newFolder = createFolder(agentLevelName); addToFolder(newFolder, level + 1, platformIdent, agentStatusData, cmrRepositoryDefinition); folder.addChild(newFolder); } } }
@Test public void testItemComposition() { Display display = new Display(); Composite shell = new Shell(display, SWT.NONE); new Item(shell, SWT.NONE) {}; assertEquals(0, shell.getChildren().length); }
public void remove(Object[] links) { for (int i = 0; i < links.length; i++) { disposeLink(links[i]); } updateMoreState(linkContainer.getChildren().length > linkNumberLimit); reflow(); }
private Hyperlink find(Object object) { Control[] children = linkContainer.getChildren(); for (int i = 0; i < children.length; i++) { Control child = children[i]; if (child.getData().equals(object)) return (Hyperlink) child; } return null; }
@Override public void refresh() { // dispose old links Control[] children = linkContainer.getChildren(); for (int i = 0; i < children.length; i++) { children[i].dispose(); } createLinks(); reflow(); }
// 通过递归遍历树 public static void display(Composite root) { for (Component c : root.getChildren()) { if (c instanceof Leaf) { // 叶子节点 c.doSomething(); } else { // 树枝节点 display((Composite) c); } } }
@Test public void testControlComposition() { Display display = new Display(); Composite composite = new Shell(display, SWT.NONE); assertEquals(0, composite.getChildren().length); Control control = new Button(composite, SWT.PUSH); assertSame(composite, control.getParent()); Control[] children = composite.getChildren(); assertSame(control, children[0]); assertEquals(1, composite.getChildren().length); children[0] = null; assertSame(control, composite.getChildren()[0]); try { new Button(null, SWT.PUSH); fail("Parent composite must not be null."); } catch (IllegalArgumentException iae) { // expected } }
public static void enableWithChildren(Composite composite, boolean enable) { composite.setEnabled(enable); for (Control child : composite.getChildren()) { if (child instanceof Composite) { enableWithChildren((Composite) child, enable); } else { child.setEnabled(enable); } } }
private void hideCustomPanelChildren() { Control[] children = customUIPanel.getChildren(); for (Control child : children) { if (child instanceof Composite && "donotremove".equals(((Composite) child).getData())) { // skip } else { child.setParent(fakeShell); } } customUIPanel.pack(); }
/** * Returns the list of components representing the input tree structure of agents divided if * needed to folders. * * @param platformIdentMap {@link Map} of {@link PlatformIdent}s and their statuses. * @param cmrRepositoryDefinition Repository agents belong to. * @return List of components. */ public static List<Component> getAgentFolderTree( Map<PlatformIdent, AgentStatusData> platformIdentMap, CmrRepositoryDefinition cmrRepositoryDefinition) { Composite dummy = new Composite(); for (Entry<PlatformIdent, AgentStatusData> entry : platformIdentMap.entrySet()) { PlatformIdent platformIdent = entry.getKey(); AgentStatusData agentStatusData = entry.getValue(); addToFolder(dummy, 0, platformIdent, agentStatusData, cmrRepositoryDefinition); } return dummy.getChildren(); }
private void createButtons() { Composite buttonArea = new Composite(shell, SWT.NONE); buttonArea.setLayout(new GridLayout(0, true)); GridData buttonData = new GridData(SWT.CENTER, SWT.CENTER, true, false); buttonData.horizontalSpan = 2; buttonArea.setLayoutData(buttonData); createButton(buttonArea, SWT.getMessage("SWT_Yes"), SWT.YES); createButton(buttonArea, SWT.getMessage("SWT_No"), SWT.NO); createButton(buttonArea, SWT.getMessage("SWT_OK"), SWT.OK); createButton(buttonArea, SWT.getMessage("SWT_Abort"), SWT.ABORT); createButton(buttonArea, SWT.getMessage("SWT_Retry"), SWT.RETRY); createButton(buttonArea, SWT.getMessage("SWT_Cancel"), SWT.CANCEL); createButton(buttonArea, SWT.getMessage("SWT_Ignore"), SWT.IGNORE); buttonArea.getChildren()[0].forceFocus(); }
@Test public void testDispose() { final List<Object> disposedWidgets = new ArrayList<Object>(); DisposeListener disposeListener = new DisposeListener() { public void widgetDisposed(DisposeEvent evt) { disposedWidgets.add(evt.getSource()); } }; Display display = new Display(); Composite shell = new Shell(display, SWT.NONE); shell.addDisposeListener(disposeListener); Button button1 = new Button(shell, SWT.PUSH); button1.addDisposeListener(disposeListener); // Ensure that dipose removes a widget from its parent and sets isDisposed() button1.dispose(); assertTrue(button1.isDisposed()); assertFalse(find(shell.getChildren(), button1)); assertSame(button1, disposedWidgets.get(0)); // Ensure that dispose may be called more than once disposedWidgets.clear(); button1.dispose(); assertTrue(button1.isDisposed()); assertEquals(0, disposedWidgets.size()); Button button2 = new Button(shell, SWT.PUSH); button2.addDisposeListener(disposeListener); shell.dispose(); assertEquals(2, disposedWidgets.size()); assertSame(shell, disposedWidgets.get(0)); assertSame(button2, disposedWidgets.get(1)); assertTrue(shell.isDisposed()); assertTrue(button2.isDisposed()); // the assert below may not work in the future since getChildren is // checkWidget()-protected assertEquals(0, ControlHolder.size(shell)); assertEquals(0, Display.getCurrent().getShells().length); // disposedWidgets.clear(); shell.dispose(); assertEquals(0, disposedWidgets.size()); assertTrue(shell.isDisposed()); }
protected int getStyle() { int result = SWT.NONE; Control[] ctrls = styleComp.getChildren(); if (ctrls.length == 0) { result = defaultStyle; } else { for (int i = 0; i < ctrls.length; i++) { if (ctrls[i] instanceof Button) { Button button = (Button) ctrls[i]; if (button.getSelection()) { Object data = button.getData("style"); if (data instanceof Integer) { int style = ((Integer) data).intValue(); result |= style; } } } } } return result; }
void onMnemonic(TraverseEvent event) { char mnemonic = _findMnemonic(text); if (mnemonic == '\0') return; if (Character.toLowerCase(event.character) != mnemonic) return; Composite control = this.getParent(); while (control != null) { Control[] children = control.getChildren(); int index = 0; while (index < children.length) { if (children[index] == this) break; index++; } index++; if (index < children.length) { if (children[index].setFocus()) { event.doit = true; event.detail = SWT.TRAVERSE_NONE; } } control = control.getParent(); } }
private void destroyExampleControls() { Control[] controls = exmplComp.getChildren(); for (int i = 0; i < controls.length; i++) { controls[i].dispose(); } }
private void buildOptions( final Composite parent, final PlatformManager platform, final Composite area, boolean rebuild) throws PlatformManagerException { if (rebuild) { Control[] kids = area.getChildren(); for (Control k : kids) { k.dispose(); } } String[] options = platform.getExplicitVMOptions(); { // max mem long max_mem = AEMemoryMonitor.getJVMLongOption(options, "-Xmx"); final int MIN_MAX_JVM = 32 * 1024 * 1024; GridData gridData = new GridData(); Label label = new Label(area, SWT.NULL); label.setLayoutData(gridData); Messages.setLanguageText(label, "jvm.max.mem", new String[] {encodeDisplayLong(MIN_MAX_JVM)}); gridData = new GridData(); gridData.widthHint = 125; final StringParameter max_vm = new StringParameter(area, "jvm.max.mem", "", false); max_vm.setLayoutData(gridData); max_vm.setValue(max_mem == -1 ? "" : encodeDisplayLong(max_mem)); max_vm.addChangeListener( new ParameterChangeAdapter() { private String last_value; public void parameterChanged(Parameter p, boolean caused_internally) { if (max_vm.isDisposed()) { max_vm.removeChangeListener(this); return; } String val = max_vm.getValue(); if (last_value != null && last_value.equals(val)) { return; } last_value = val; try { long max_mem = decodeDisplayLong(val); if (max_mem < MIN_MAX_JVM) { throw (new Exception("Min=" + encodeDisplayLong(MIN_MAX_JVM))); } String[] options = platform.getExplicitVMOptions(); options = AEMemoryMonitor.setJVMLongOption(options, "-Xmx", max_mem); long min_mem = AEMemoryMonitor.getJVMLongOption(options, "-Xms"); if (min_mem == -1 || min_mem > max_mem) { options = AEMemoryMonitor.setJVMLongOption(options, "-Xms", max_mem); } platform.setExplicitVMOptions(options); buildOptions(parent, platform, area, true); } catch (Throwable e) { String param_name = MessageText.getString("jvm.max.mem"); int pos = param_name.indexOf('['); if (pos != -1) { param_name = param_name.substring(0, pos).trim(); } MessageBoxShell mb = new MessageBoxShell( SWT.ICON_ERROR | SWT.OK, MessageText.getString("ConfigView.section.invalid.value.title"), MessageText.getString( "ConfigView.section.invalid.value", new String[] {val, param_name, Debug.getNestedExceptionMessage(e)})); mb.setParent(parent.getShell()); mb.open(null); } } }); label = new Label(area, SWT.NULL); gridData = new GridData(GridData.FILL_HORIZONTAL); label.setLayoutData(gridData); Long max_heap_mb = AEMemoryMonitor.getMaxHeapMB(); if (max_heap_mb > 0) { Messages.setLanguageText( label, "jvm.max.mem.current", new String[] { DisplayFormatters.formatByteCountToKiBEtc(max_heap_mb * 1024 * 1024, true) }); } } { // min mem final int MIN_MIN_JVM = 8 * 1024 * 1024; long min_mem = AEMemoryMonitor.getJVMLongOption(options, "-Xms"); GridData gridData = new GridData(); Label label = new Label(area, SWT.NULL); label.setLayoutData(gridData); Messages.setLanguageText(label, "jvm.min.mem", new String[] {encodeDisplayLong(MIN_MIN_JVM)}); gridData = new GridData(); gridData.widthHint = 125; final StringParameter min_vm = new StringParameter(area, "jvm.min.mem", "", false); min_vm.setLayoutData(gridData); min_vm.setValue(min_mem == -1 ? "" : encodeDisplayLong(min_mem)); min_vm.addChangeListener( new ParameterChangeAdapter() { private String last_value; public void parameterChanged(Parameter p, boolean caused_internally) { if (min_vm.isDisposed()) { min_vm.removeChangeListener(this); return; } String val = min_vm.getValue(); if (last_value != null && last_value.equals(val)) { return; } last_value = val; try { long min_mem = decodeDisplayLong(val); if (min_mem < MIN_MIN_JVM) { throw (new Exception("Min=" + encodeDisplayLong(MIN_MIN_JVM))); } String[] options = platform.getExplicitVMOptions(); options = AEMemoryMonitor.setJVMLongOption(options, "-Xms", min_mem); long max_mem = AEMemoryMonitor.getJVMLongOption(options, "-Xmx"); if (max_mem == -1 || max_mem < min_mem) { options = AEMemoryMonitor.setJVMLongOption(options, "-Xmx", min_mem); } platform.setExplicitVMOptions(options); buildOptions(parent, platform, area, true); } catch (Throwable e) { String param_name = MessageText.getString("jvm.min.mem"); int pos = param_name.indexOf('['); if (pos != -1) { param_name = param_name.substring(0, pos).trim(); } MessageBoxShell mb = new MessageBoxShell( SWT.ICON_ERROR | SWT.OK, MessageText.getString("ConfigView.section.invalid.value.title"), MessageText.getString( "ConfigView.section.invalid.value", new String[] {val, param_name, Debug.getNestedExceptionMessage(e)})); mb.setParent(parent.getShell()); mb.open(null); } } }); label = new Label(area, SWT.NULL); gridData = new GridData(GridData.FILL_HORIZONTAL); label.setLayoutData(gridData); } { // max DIRECT mem final int MIN_DIRECT_JVM = 32 * 1024 * 1024; final String OPTION_KEY = "-XX:MaxDirectMemorySize="; long max_direct = AEMemoryMonitor.getJVMLongOption(options, OPTION_KEY); GridData gridData = new GridData(); Label label = new Label(area, SWT.NULL); label.setLayoutData(gridData); Messages.setLanguageText( label, "jvm.max.direct.mem", new String[] {encodeDisplayLong(MIN_DIRECT_JVM)}); gridData = new GridData(); gridData.widthHint = 125; final StringParameter max_direct_vm = new StringParameter(area, "jvm.max.direct.mem", "", false); max_direct_vm.setLayoutData(gridData); max_direct_vm.setValue(max_direct == -1 ? "" : encodeDisplayLong(max_direct)); max_direct_vm.addChangeListener( new ParameterChangeAdapter() { private String last_value; public void parameterChanged(Parameter p, boolean caused_internally) { if (max_direct_vm.isDisposed()) { max_direct_vm.removeChangeListener(this); return; } String val = max_direct_vm.getValue(); if (last_value != null && last_value.equals(val)) { return; } last_value = val; try { long max_direct = decodeDisplayLong(val); if (max_direct < MIN_DIRECT_JVM) { throw (new Exception("Min=" + encodeDisplayLong(MIN_DIRECT_JVM))); } String[] options = platform.getExplicitVMOptions(); options = AEMemoryMonitor.setJVMLongOption(options, OPTION_KEY, max_direct); platform.setExplicitVMOptions(options); buildOptions(parent, platform, area, true); } catch (Throwable e) { String param_name = MessageText.getString("jvm.max.direct.mem"); int pos = param_name.indexOf('['); if (pos != -1) { param_name = param_name.substring(0, pos).trim(); } MessageBoxShell mb = new MessageBoxShell( SWT.ICON_ERROR | SWT.OK, MessageText.getString("ConfigView.section.invalid.value.title"), MessageText.getString( "ConfigView.section.invalid.value", new String[] {val, param_name, Debug.getNestedExceptionMessage(e)})); mb.setParent(parent.getShell()); mb.open(null); } } }); label = new Label(area, SWT.NULL); gridData = new GridData(GridData.FILL_HORIZONTAL); label.setLayoutData(gridData); Messages.setLanguageText(label, "jvm.max.direct.mem.info"); } // all options Label label = new Label(area, SWT.NULL); GridData gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.horizontalSpan = 3; label.setLayoutData(gridData); Messages.setLanguageText(label, "jvm.options.summary"); for (String option : options) { label = new Label(area, SWT.NULL); label.setText(option); gridData = new GridData(); gridData.horizontalSpan = 3; gridData.horizontalIndent = 20; label.setLayoutData(gridData); } if (rebuild) { parent.layout(true, true); } }