public void update() { tick++; if (tick == 2) { internal = new LinkedHashSet<Class>( ((MyClassLoader) Trampoline2.trampoline.getClassLoader()).getAllLoadedClasses()); ; // ;//System.out.println(" ----------- reload plugin ----------"); populateTree(); } else if (tick > 2) { Control c = Launcher.display.getFocusControl(); if (c == null) return; Shell s = c.getShell(); if (s.getText().trim().length() == 0) return; Set<Class> allClass = ((MyClassLoader) Trampoline2.trampoline.getClassLoader()).getAllLoadedClasses(); int hashNow = allClass.hashCode(); if (hashNow != hashWas && willRep < 0) { willRep = 5; } } willRep--; if (willRep == 0) { populateTree(); } }
public void refresh(boolean dirty) { String text = shell.getText(); if (text.indexOf("*") == -1) text = "*" + text; shell.setText(text); if (dirty) { mParentViewer.refresh(true); } baseCompositeMapPage.refresh(false); }
private static void writeText(final Shell shell) throws IOException { String text = shell.getText(); if (WidgetLCAUtil.hasChanged(shell, PROP_TEXT, text, "")) { // JSWriter writer = JSWriter.getWriterFor( shell ); text = WidgetLCAUtil.escapeText(text, false); // writer.set( JSConst.QX_FIELD_CAPTION, text ); IWidgetSynchronizer synchronizer = WidgetSynchronizerFactory.getSynchronizerForWidget(shell); synchronizer.setWidgetProperty(JSConst.QX_FIELD_CAPTION, text); } }
public void preserveValues(final Widget widget) { ControlLCAUtil.preserveValues((Control) widget); Shell shell = (Shell) widget; IWidgetAdapter adapter = WidgetUtil.getAdapter(shell); adapter.preserve(PROP_ACTIVE_CONTROL, getActiveControl(shell)); adapter.preserve(PROP_ACTIVE_SHELL, shell.getDisplay().getActiveShell()); adapter.preserve(PROP_TEXT, shell.getText()); adapter.preserve(PROP_IMAGE, shell.getImage()); adapter.preserve(PROP_ALPHA, new Integer(shell.getAlpha())); adapter.preserve(PROP_MODE, getMode(shell)); adapter.preserve(PROP_FULLSCREEN, Boolean.valueOf(shell.getFullScreen())); adapter.preserve(PROP_SHELL_LISTENER, Boolean.valueOf(ShellEvent.hasListener(shell))); adapter.preserve(PROP_SHELL_MENU, shell.getMenuBar()); adapter.preserve(PROP_MINIMUM_SIZE, shell.getMinimumSize()); WidgetLCAUtil.preserveCustomVariant(shell); }
@Override public void refreshView(List<Exception> exceptions) { EventDefinition.refreshMaxPassPrefsEventInfo(); Stock viewStateParams = hightlitedEventModel.getViewParamRoot(); if (viewStateParams != null) { checkChartSelectionValidity(); chartDisplayStrategy.highLight(highligtedId, viewStateParams, false); } chartDisplayStrategy.refreshView(exceptions); if (isVisible()) { Shell[] childrenShells = this.getShell().getShells(); for (Shell child : childrenShells) { if (child.getText().contains("Warning")) child.forceActive(); } } }
public void balloonNotify(final Shell shell, final String message) { if (toolTip == null) return; try { if (SwtUtils.isNotUIThread()) { SwtUtils.DISPLAY.asyncExec( new Runnable() { @Override public void run() { balloonNotify(shell, message); } }); return; } toolTip.setText(shell.getText()); toolTip.setMessage(message); toolTip.setVisible(true); } catch (SWTException e) { } }
private boolean closeAddressBook() { if (isModified) { // ask user if they want to save current address book MessageBox box = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO | SWT.CANCEL); box.setText(shell.getText()); box.setMessage(resAddressBook.getString("Close_save")); int choice = box.open(); if (choice == SWT.CANCEL) { return false; } else if (choice == SWT.YES) { if (!save()) return false; } } TableItem[] items = table.getItems(); for (int i = 0; i < items.length; i++) { items[i].dispose(); } return true; }
public void testCreateView() { final MWindow window = createWindowWithOneView(); wb = new E4Workbench(window, appContext); Widget topWidget = (Widget) window.getWidget(); assertTrue(topWidget instanceof Shell); Shell shell = (Shell) topWidget; assertEquals("MyWindow", shell.getText()); Control[] controls = shell.getChildren(); assertEquals(1, controls.length); SashForm sash = (SashForm) controls[0]; Control[] sashChildren = sash.getChildren(); assertEquals(1, sashChildren.length); CTabFolder folder = (CTabFolder) sashChildren[0]; assertEquals(1, folder.getItemCount()); Control c = folder.getItem(0).getControl(); assertTrue(c instanceof Composite); Control[] viewPart = ((Composite) c).getChildren(); assertEquals(1, viewPart.length); assertTrue(viewPart[0] instanceof Tree); }
public void testContextChildren() { final MWindow window = createWindowWithOneView(); wb = new E4Workbench(window, appContext); Widget topWidget = (Widget) window.getWidget(); assertTrue(topWidget instanceof Shell); Shell shell = (Shell) topWidget; assertEquals("MyWindow", shell.getText()); // should get the window context IEclipseContext child = appContext.getActiveChild(); assertNotNull(child); assertEquals(window.getContext(), child); MPart modelPart = getContributedPart(window); assertNotNull(modelPart); assertEquals(window, modelPart.getParent().getParent().getParent()); // "activate" the part, same as (in theory) an // SWT.Activate event. AbstractPartRenderer factory = (AbstractPartRenderer) modelPart.getRenderer(); factory.activate(modelPart); IEclipseContext next = child.getActiveChild(); while (next != null) { child = next; next = child.getActiveChild(); if (next == child) { fail("Cycle detected in part context"); break; } } assertFalse(window.getContext() == child); MPart contextPart = (MPart) child.get(MPart.class.getName()); assertNotNull(contextPart); assertEquals(window, contextPart.getParent().getParent().getParent()); }
void refreshDifference() { DeviceData info = display.getDeviceData(); if (!info.tracking) { MessageBox dialog = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK); dialog.setText(shell.getText()); dialog.setMessage("Warning: Device is not tracking resource allocation"); // $NON-NLS-1$ dialog.open(); } Object[] newObjects = info.objects; Error[] newErrors = info.errors; Object[] diffObjects = new Object[newObjects.length]; Error[] diffErrors = new Error[newErrors.length]; int count = 0; for (int i = 0; i < newObjects.length; i++) { int index = 0; while (index < oldObjects.length) { if (newObjects[i] == oldObjects[index]) break; index++; } if (index == oldObjects.length) { diffObjects[count] = newObjects[i]; diffErrors[count] = newErrors[i]; count++; } } objects = new Object[count]; errors = new Error[count]; System.arraycopy(diffObjects, 0, objects, 0, count); System.arraycopy(diffErrors, 0, errors, 0, count); list.removeAll(); text.setText(""); // $NON-NLS-1$ canvas.redraw(); for (int i = 0; i < objects.length; i++) { list.add(objectName(objects[i])); } refreshLabel(); layout(); }
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Text Editor"); Menu bar = new Menu(shell, SWT.BAR); shell.setMenuBar(bar); MenuItem fileItem = new MenuItem(bar, SWT.CASCADE); fileItem.setText("&File"); Menu fileMenu = new Menu(shell, SWT.DROP_DOWN); fileItem.setMenu(fileMenu); MenuItem saveItem = new MenuItem(fileMenu, SWT.PUSH); saveItem.setText("&Save\tCtrl+S"); saveItem.setAccelerator(SWT.MOD1 + 'S'); saveItem.addListener(SWT.Selection, e -> shell.setModified(false)); MenuItem exitItem = new MenuItem(fileMenu, SWT.PUSH); exitItem.setText("Exit"); exitItem.addListener(SWT.Selection, e -> shell.close()); Text text = new Text(shell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); text.addListener(SWT.Modify, e -> shell.setModified(true)); shell.addListener( SWT.Close, e -> { if (shell.getModified()) { MessageBox box = new MessageBox(shell, SWT.PRIMARY_MODAL | SWT.OK | SWT.CANCEL); box.setText(shell.getText()); box.setMessage("You have unsaved changes, do you want to exit?"); e.doit = box.open() == SWT.OK; } }); shell.setLayout(new FillLayout()); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
public String getText() { return shell.getText(); }
@SuppressWarnings("unchecked") public void prepareForOpen() { Point contentsSize = contents.getSize(); Point titleSize = new Point(0, 0); boolean showTitle = ((style & (SWT.CLOSE | SWT.TITLE)) != 0); if (showTitle) { if (titleLabel == null) { titleLabel = new Label(shell, SWT.NONE); titleLabel.setBackground(shell.getBackground()); titleLabel.setForeground(shell.getForeground()); FontData[] fds = shell.getFont().getFontData(); for (int i = 0; i < fds.length; i++) { fds[i].setStyle(fds[i].getStyle() | SWT.BOLD); } final Font font = new Font(shell.getDisplay(), fds); titleLabel.addListener( SWT.Dispose, new Listener() { @Override public void handleEvent(Event event) { font.dispose(); } }); titleLabel.setFont(font); selectionControls.add(titleLabel); } String titleText = shell.getText(); titleLabel.setText(titleText == null ? "" : titleText); titleLabel.pack(); titleSize = titleLabel.getSize(); final Image titleImage = shell.getImage(); if (titleImageLabel == null && shell.getImage() != null) { titleImageLabel = new Canvas(shell, SWT.NONE); titleImageLabel.setBackground(shell.getBackground()); titleImageLabel.setBounds(titleImage.getBounds()); titleImageLabel.addListener( SWT.Paint, new Listener() { @Override public void handleEvent(Event event) { event.gc.drawImage(titleImage, 0, 0); } }); Point tilSize = titleImageLabel.getSize(); titleSize.x += tilSize.x + titleWidgetSpacing; if (tilSize.y > titleSize.y) titleSize.y = tilSize.y; selectionControls.add(titleImageLabel); } if (systemControlsBar == null && (style & SWT.CLOSE) != 0) { // Color closeFG = shell.getForeground(), closeBG = shell.getBackground(); // Color closeFG = shell.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY), closeBG = // shell.getBackground(); Color closeFG = shell.getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND), closeBG = shell.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND); final Image closeImage = createCloseImage(shell.getDisplay(), closeBG, closeFG); shell.addListener( SWT.Dispose, new Listener() { @Override public void handleEvent(Event event) { closeImage.dispose(); } }); systemControlsBar = new ToolBar(shell, SWT.FLAT); systemControlsBar.setBackground(closeBG); systemControlsBar.setForeground(closeFG); ToolItem closeItem = new ToolItem(systemControlsBar, SWT.PUSH); closeItem.setImage(closeImage); closeItem.addListener( SWT.Selection, new Listener() { @Override public void handleEvent(Event event) { shell.close(); } }); systemControlsBar.pack(); Point closeSize = systemControlsBar.getSize(); titleSize.x += closeSize.x + titleWidgetSpacing; if (closeSize.y > titleSize.y) titleSize.y = closeSize.y; } titleSize.y += titleSpacing; if (titleSize.x > contentsSize.x) { contentsSize.x = titleSize.x; contents.setSize(contentsSize.x, contentsSize.y); } contentsSize.y += titleSize.y; } Rectangle screen = shell.getDisplay().getClientArea(); int anchor = preferredAnchor; if (anchor != SWT.NONE && autoAnchor && locX != Integer.MIN_VALUE) { if ((anchor & SWT.LEFT) != 0) { if (locX + contentsSize.x + marginLeft + marginRight - 16 >= screen.x + screen.width) anchor = anchor - SWT.LEFT + SWT.RIGHT; } else // RIGHT { if (locX - contentsSize.x - marginLeft - marginRight + 16 < screen.x) anchor = anchor - SWT.RIGHT + SWT.LEFT; } if ((anchor & SWT.TOP) != 0) { if (locY + contentsSize.y + 20 + marginTop + marginBottom >= screen.y + screen.height) anchor = anchor - SWT.TOP + SWT.BOTTOM; } else // BOTTOM { if (locY - contentsSize.y - 20 - marginTop - marginBottom < screen.y) anchor = anchor - SWT.BOTTOM + SWT.TOP; } } final Point shellSize = (anchor == SWT.NONE) ? new Point( contentsSize.x + marginLeft + marginRight, contentsSize.y + marginTop + marginBottom) : new Point( contentsSize.x + marginLeft + marginRight, contentsSize.y + marginTop + marginBottom + 20); if (shellSize.x < 54 + marginLeft + marginRight) shellSize.x = 54 + marginLeft + marginRight; if (anchor == SWT.NONE) { if (shellSize.y < 10 + marginTop + marginBottom) shellSize.y = 10 + marginTop + marginBottom; } else { if (shellSize.y < 30 + marginTop + marginBottom) shellSize.y = 30 + marginTop + marginBottom; } shell.setSize(shellSize); int titleLocY = marginTop + (((anchor & SWT.TOP) != 0) ? 20 : 0); contents.setLocation(marginLeft, titleSize.y + titleLocY); if (showTitle) { int realTitleHeight = titleSize.y - titleSpacing; if (titleImageLabel != null) { titleImageLabel.setLocation( marginLeft, titleLocY + (realTitleHeight - titleImageLabel.getSize().y) / 2); titleLabel.setLocation( marginLeft + titleImageLabel.getSize().x + titleWidgetSpacing, titleLocY + (realTitleHeight - titleLabel.getSize().y) / 2); } else titleLabel.setLocation( marginLeft, titleLocY + (realTitleHeight - titleLabel.getSize().y) / 2); if (systemControlsBar != null) systemControlsBar.setLocation( shellSize.x - marginRight - systemControlsBar.getSize().x, titleLocY + (realTitleHeight - systemControlsBar.getSize().y) / 2); } final Region region = new Region(); region.add(createOutline(shellSize, anchor, true)); shell.setRegion(region); shell.addListener( SWT.Dispose, new Listener() { @Override public void handleEvent(Event event) { region.dispose(); } }); final int[] outline = createOutline(shellSize, anchor, false); shell.addListener( SWT.Paint, new Listener() { @Override public void handleEvent(Event event) { event.gc.drawPolygon(outline); } }); if (locX != Integer.MIN_VALUE) { Point shellLoc = new Point(locX, locY); if ((anchor & SWT.BOTTOM) != 0) shellLoc.y = shellLoc.y - shellSize.y + 1; if ((anchor & SWT.LEFT) != 0) shellLoc.x -= 15; else if ((anchor & SWT.RIGHT) != 0) shellLoc.x = shellLoc.x - shellSize.x + 16; if (autoAnchor) { if (shellLoc.x < screen.x) shellLoc.x = screen.x; else if (shellLoc.x > screen.x + screen.width - shellSize.x) shellLoc.x = screen.x + screen.width - shellSize.x; if (anchor == SWT.NONE) { if (shellLoc.y < screen.y) shellLoc.y = screen.y; else if (shellLoc.y > screen.y + screen.height - shellSize.y) shellLoc.y = screen.y + screen.height - shellSize.y; } } shell.setLocation(shellLoc); } }
@Override public String getTitle() { return shell.getText(); }