protected void optionsSectionLayout(Class<?> PKG, String prefix) { gDetails = new Group(shell, SWT.SHADOW_ETCHED_IN); fdLocal.bottom = new FormAttachment(100, -510); gDetails.setText(BaseMessages.getString(PKG, prefix + ".DetailsGroup.Label")); props.setLook(gDetails); // The layout gDetails.setLayout(new FormLayout()); fdDetails = new FormData(); fdDetails.top = new FormAttachment(gLocal, 15); fdDetails.right = new FormAttachment(100, -15); fdDetails.left = new FormAttachment(0, 15); gDetails.setBackground(shell.getBackground()); // the default looks ugly gDetails.setLayoutData(fdDetails); optionsSectionControls(); }
@SuppressWarnings("unchecked") private BalloonWindow(Display display, Shell parent, final int style) { this.style = style; int shellStyle = style & (SWT.ON_TOP | SWT.TOOL); this.shell = (display != null) ? new Shell(display, SWT.NO_TRIM | shellStyle) : new Shell(parent, SWT.NO_TRIM | shellStyle); this.contents = new Composite(shell, SWT.NONE); final Color c = new Color(shell.getDisplay(), 255, 255, 225); shell.setBackground(c); shell.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_BLACK)); contents.setBackground(shell.getBackground()); contents.setForeground(shell.getForeground()); selectionControls.add(shell); selectionControls.add(contents); final Listener globalListener = new Listener() { @Override public void handleEvent(Event event) { Widget w = event.widget; for (int i = selectionControls.size() - 1; i >= 0; i--) { if (selectionControls.get(i) == w) { if ((style & SWT.CLOSE) != 0) { for (int j = selectionListeners.size() - 1; j >= 0; j--) ((Listener) selectionListeners.get(j)).handleEvent(event); } else { shell.close(); } event.doit = false; } } } }; shell.addListener( SWT.Show, new Listener() { @Override public void handleEvent(Event event) { if (!addedGlobalListener) { shell.getDisplay().addFilter(SWT.MouseDown, globalListener); addedGlobalListener = true; } } }); shell.addListener( SWT.Hide, new Listener() { @Override public void handleEvent(Event event) { if (addedGlobalListener) { shell.getDisplay().removeFilter(SWT.MouseDown, globalListener); addedGlobalListener = false; } } }); shell.addListener( SWT.Dispose, new Listener() { @Override public void handleEvent(Event event) { if (addedGlobalListener) { shell.getDisplay().removeFilter(SWT.MouseDown, globalListener); addedGlobalListener = false; } c.dispose(); } }); }
@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); } }
public static void main(String[] args) { final Display display = new Display(); // Shell must be created with style SWT.NO_TRIM final Shell shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP); shell.setBackground(display.getSystemColor(SWT.COLOR_RED)); // define a region that looks like a key hole Region region = new Region(); region.add(circle(67, 67, 67)); region.subtract(circle(20, 67, 50)); region.subtract(new int[] {67, 50, 55, 105, 79, 105}); // define the shape of the shell using setRegion shell.setRegion(region); Rectangle size = region.getBounds(); shell.setSize(size.width, size.height); // add ability to move shell around Listener l = new Listener() { /** The x/y of the MouseDown, relative to top-left of the shell. */ Point origin; @Override public void handleEvent(Event e) { switch (e.type) { case SWT.MouseDown: Point point = shell.toDisplay(e.x, e.y); Point loc = shell.getLocation(); origin = new Point(point.x - loc.x, point.y - loc.y); break; case SWT.MouseUp: origin = null; break; case SWT.MouseMove: if (origin != null) { Point p = display.map(shell, null, e.x, e.y); shell.setLocation(p.x - origin.x, p.y - origin.y); } break; } } }; shell.addListener(SWT.MouseDown, l); shell.addListener(SWT.MouseUp, l); shell.addListener(SWT.MouseMove, l); // add ability to close shell Button b = new Button(shell, SWT.PUSH); b.setBackground(shell.getBackground()); b.setText("close"); b.pack(); b.setLocation(10, 68); b.addListener( SWT.Selection, new Listener() { @Override public void handleEvent(Event e) { shell.close(); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } region.dispose(); display.dispose(); }
protected void environmentTypeSectionLayout(Class<?> PKG, String prefix) { gLocal = new Group(shell, SWT.SHADOW_ETCHED_IN); gLocal.setText(BaseMessages.getString(PKG, prefix + ".LocalGroup.Label")); gLocal.setLayout(new FormLayout()); props.setLook(gLocal); fdLocal = new FormData(); fdLocal.top = new FormAttachment(0, 15); fdLocal.right = new FormAttachment(100, -15); fdLocal.left = new FormAttachment(0, 15); gLocal.setBackground(shell.getBackground()); // the default looks ugly gLocal.setLayoutData(fdLocal); wExecLocal = new Button(gLocal, SWT.RADIO); wExecLocal.setText(BaseMessages.getString(PKG, prefix + ".ExecLocal.Label")); wExecLocal.setToolTipText(BaseMessages.getString(PKG, prefix + ".ExecLocal.Tooltip")); props.setLook(wExecLocal); fdExecLocal = new FormData(); fdExecLocal.top = new FormAttachment(11); wExecLocal.setLayoutData(fdExecLocal); wExecLocal.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { stackedLayout.topControl = localOptionsComposite; stackedLayoutComposite.layout(); } }); wExecRemote = new Button(gLocal, SWT.RADIO); wExecRemote.setText(BaseMessages.getString(PKG, prefix + ".ExecRemote.Label")); wExecRemote.setToolTipText(BaseMessages.getString(PKG, prefix + ".ExecRemote.Tooltip")); props.setLook(wExecRemote); fdExecLocal.left = new FormAttachment(wExecRemote, 0, SWT.LEFT); fdExecRemote = new FormData(); fdExecRemote.left = new FormAttachment(0, 10); fdExecRemote.top = new FormAttachment(wExecLocal, 7); wExecRemote.setLayoutData(fdExecRemote); wExecRemote.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { stackedLayout.topControl = serverOptionsComposite; stackedLayoutComposite.layout(); } }); // separator environmentSeparator = new Label(gLocal, SWT.SEPARATOR | SWT.VERTICAL); FormData fd_environmentSeparator = new FormData(); fd_environmentSeparator.height = 83; fd_environmentSeparator.top = new FormAttachment(wExecLocal, 0, SWT.TOP); fd_environmentSeparator.left = new FormAttachment(0, 113); environmentSeparator.setLayoutData(fd_environmentSeparator); // stacked layout composite stackedLayoutComposite = new Composite(gLocal, SWT.NONE); props.setLook(stackedLayoutComposite); stackedLayout = new StackLayout(); stackedLayoutComposite.setLayout(stackedLayout); FormData fd_stackedLayoutComposite = new FormData(); fd_stackedLayoutComposite.top = new FormAttachment(0); fd_stackedLayoutComposite.left = new FormAttachment(environmentSeparator, 7); fd_stackedLayoutComposite.bottom = new FormAttachment(100, -5); fd_stackedLayoutComposite.right = new FormAttachment(100, -7); stackedLayoutComposite.setLayoutData(fd_stackedLayoutComposite); localOptionsComposite = new Composite(stackedLayoutComposite, SWT.NONE); localOptionsComposite.setLayout(new FormLayout()); props.setLook(localOptionsComposite); serverOptionsComposite = new Composite(stackedLayoutComposite, SWT.NONE); serverOptionsComposite.setLayout(new FormLayout()); props.setLook(serverOptionsComposite); stackedLayout.topControl = localOptionsComposite; localOptionsComposite(PKG, prefix); serverOptionsComposite(PKG, prefix); }
private void deleteQueuesOrExchanges(Shell parent, final VhostOperations op) { Table table; String windowTitle; String dialogueMessage; final String feedBackMessage; final String failureFeedBackMessage; if (op.equals(VhostOperations.DELETE_QUEUE)) { table = _queueTable; windowTitle = "Delete Queue(s)"; dialogueMessage = "Delete Queue(s): "; feedBackMessage = "Queue(s) deleted"; failureFeedBackMessage = "Error deleting Queue(s)"; } else { table = _exchangeTable; windowTitle = "Delete Exchange(s)"; dialogueMessage = "Delete Exchange(s): "; feedBackMessage = "Exchange(s) deleted"; failureFeedBackMessage = "Error deleting Exchange(s)"; } int selectionIndex = table.getSelectionIndex(); if (selectionIndex == -1) { return; } int[] selectedIndices = table.getSelectionIndices(); final ArrayList<ManagedBean> selectedMBeans = new ArrayList<ManagedBean>(); for (int index = 0; index < selectedIndices.length; index++) { ManagedBean selectedMBean = (ManagedBean) table.getItem(selectedIndices[index]).getData(); selectedMBeans.add(selectedMBean); } final Shell shell = ViewUtility.createModalDialogShell(parent, windowTitle); _toolkit.createLabel(shell, dialogueMessage).setBackground(shell.getBackground()); final Text headerText = new Text(shell, SWT.WRAP | SWT.V_SCROLL | SWT.BORDER); headerText.setEditable(false); GridData data = new GridData(SWT.FILL, SWT.FILL, false, false); data.minimumHeight = 150; data.heightHint = 150; data.minimumWidth = 400; data.widthHint = 400; headerText.setLayoutData(data); String lineSeperator = System.getProperty("line.separator"); for (ManagedBean mbean : selectedMBeans) { headerText.append(mbean.getName() + lineSeperator); } headerText.setSelection(0); Composite okCancelButtonsComp = _toolkit.createComposite(shell); okCancelButtonsComp.setBackground(shell.getBackground()); okCancelButtonsComp.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, true)); okCancelButtonsComp.setLayout(new GridLayout(2, false)); Button okButton = _toolkit.createButton(okCancelButtonsComp, "OK", SWT.PUSH); okButton.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false)); Button cancelButton = _toolkit.createButton(okCancelButtonsComp, "Cancel", SWT.PUSH); cancelButton.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false)); okButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { shell.dispose(); try { // perform the deletes for (ManagedBean mbean : selectedMBeans) { switch (op) { case DELETE_QUEUE: _vhmb.deleteQueue(mbean.getName()); _serverRegistry.removeManagedObject(mbean); break; case DELETE_EXCHANGE: _vhmb.unregisterExchange(mbean.getName()); break; } // remove the mbean from the server registry now instead of // waiting for an mbean Unregistration Notification to do it _serverRegistry.removeManagedObject(mbean); } ViewUtility.operationResultFeedback(null, feedBackMessage, null); } catch (Exception e1) { ViewUtility.operationFailedStatusBarMessage(failureFeedBackMessage); MBeanUtility.handleException(_mbean, e1); } refresh(_mbean); ; } }); cancelButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { shell.dispose(); } }); shell.setDefaultButton(okButton); shell.pack(); ViewUtility.centerChildInParentShell(parent, shell); shell.open(); }
private void createExchange(final Shell parent) { final Shell shell = ViewUtility.createModalDialogShell(parent, "Create Exchange"); Composite nameComposite = _toolkit.createComposite(shell, SWT.NONE); nameComposite.setBackground(shell.getBackground()); nameComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); nameComposite.setLayout(new GridLayout(2, false)); _toolkit.createLabel(nameComposite, "Name:").setBackground(shell.getBackground()); final Text nameText = new Text(nameComposite, SWT.BORDER); nameText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); Composite typeComposite = _toolkit.createComposite(shell, SWT.NONE); typeComposite.setBackground(shell.getBackground()); typeComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); typeComposite.setLayout(new GridLayout(2, false)); String[] exchangeTypes; if (_ApiVersion.greaterThanOrEqualTo(1, 3)) // if the server supports Qpid JMX API 1.3 { // request the current exchange types from the broker try { exchangeTypes = _vhmb.getExchangeTypes(); } catch (IOException e1) { exchangeTypes = DEFAULT_EXCHANGE_TYPE_VALUES.toArray(new String[DEFAULT_EXCHANGE_TYPE_VALUES.size()]); } } else // use the fallback defaults. { exchangeTypes = DEFAULT_EXCHANGE_TYPE_VALUES.toArray(new String[DEFAULT_EXCHANGE_TYPE_VALUES.size()]); } _toolkit.createLabel(typeComposite, "Type:").setBackground(shell.getBackground()); final org.eclipse.swt.widgets.List typeList = new org.eclipse.swt.widgets.List(typeComposite, SWT.SINGLE | SWT.BORDER); typeList.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); typeList.setItems(exchangeTypes); Composite durableComposite = _toolkit.createComposite(shell, SWT.NONE); durableComposite.setBackground(shell.getBackground()); GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false); gridData.minimumWidth = 220; durableComposite.setLayoutData(gridData); durableComposite.setLayout(new GridLayout(2, false)); _toolkit.createLabel(durableComposite, "Durable:").setBackground(shell.getBackground()); final Button durableButton = new Button(durableComposite, SWT.CHECK); durableButton.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, false)); Composite okCancelButtonsComp = _toolkit.createComposite(shell); okCancelButtonsComp.setBackground(shell.getBackground()); okCancelButtonsComp.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, true)); okCancelButtonsComp.setLayout(new GridLayout(2, false)); Button okButton = _toolkit.createButton(okCancelButtonsComp, "OK", SWT.PUSH); okButton.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false)); Button cancelButton = _toolkit.createButton(okCancelButtonsComp, "Cancel", SWT.PUSH); cancelButton.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false)); okButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String name = nameText.getText(); if (name == null || name.length() == 0) { ViewUtility.popupErrorMessage("Create Exchange", "Please enter a valid name"); return; } int selectedTypeIndex = typeList.getSelectionIndex(); if (selectedTypeIndex == -1) { ViewUtility.popupErrorMessage("Create Exchange", "Please select an Exchange type"); return; } String type = typeList.getItem(selectedTypeIndex); boolean durable = durableButton.getSelection(); shell.dispose(); try { _vhmb.createNewExchange(name, type, durable); ViewUtility.operationResultFeedback(null, "Created Exchange", null); try { // delay to allow mbean registration notification processing Thread.sleep(250); } catch (InterruptedException ie) { // ignore } } catch (Exception e5) { ViewUtility.operationFailedStatusBarMessage("Error creating Exchange"); MBeanUtility.handleException(_mbean, e5); } refresh(_mbean); } }); cancelButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { shell.dispose(); } }); shell.setDefaultButton(okButton); shell.pack(); ViewUtility.centerChildInParentShell(parent, shell); shell.open(); }
private void createQueue(final Shell parent) { final Shell shell = ViewUtility.createModalDialogShell(parent, "Create Queue"); Composite nameComposite = _toolkit.createComposite(shell, SWT.NONE); nameComposite.setBackground(shell.getBackground()); nameComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); nameComposite.setLayout(new GridLayout(2, false)); _toolkit.createLabel(nameComposite, "Name:").setBackground(shell.getBackground()); final Text nameText = new Text(nameComposite, SWT.BORDER); nameText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); Composite ownerComposite = _toolkit.createComposite(shell, SWT.NONE); ownerComposite.setBackground(shell.getBackground()); ownerComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); ownerComposite.setLayout(new GridLayout(2, false)); _toolkit.createLabel(ownerComposite, "Owner (optional):").setBackground(shell.getBackground()); final Text ownerText = new Text(ownerComposite, SWT.BORDER); ownerText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); Composite durableComposite = _toolkit.createComposite(shell, SWT.NONE); durableComposite.setBackground(shell.getBackground()); GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false); gridData.minimumWidth = 220; durableComposite.setLayoutData(gridData); durableComposite.setLayout(new GridLayout(2, false)); _toolkit.createLabel(durableComposite, "Durable:").setBackground(shell.getBackground()); final Button durableButton = new Button(durableComposite, SWT.CHECK); durableButton.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, false)); Composite okCancelButtonsComp = _toolkit.createComposite(shell); okCancelButtonsComp.setBackground(shell.getBackground()); okCancelButtonsComp.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, true)); okCancelButtonsComp.setLayout(new GridLayout(2, false)); Button okButton = _toolkit.createButton(okCancelButtonsComp, "OK", SWT.PUSH); okButton.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false)); Button cancelButton = _toolkit.createButton(okCancelButtonsComp, "Cancel", SWT.PUSH); cancelButton.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false)); okButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String name = nameText.getText(); if (name == null || name.length() == 0) { ViewUtility.popupErrorMessage("Create Queue", "Please enter a valid name"); return; } String owner = ownerText.getText(); if (owner != null && owner.length() == 0) { owner = null; } boolean durable = durableButton.getSelection(); shell.dispose(); try { _vhmb.createNewQueue(name, owner, durable); ViewUtility.operationResultFeedback(null, "Created Queue", null); try { // delay to allow mbean registration notification processing Thread.sleep(250); } catch (InterruptedException ie) { // ignore } } catch (Exception e5) { ViewUtility.operationFailedStatusBarMessage("Error creating Queue"); MBeanUtility.handleException(_mbean, e5); } refresh(_mbean); } }); cancelButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { shell.dispose(); } }); shell.setDefaultButton(okButton); shell.pack(); ViewUtility.centerChildInParentShell(parent, shell); shell.open(); }
/** * Creates the dialog's contents * * @param shell the dialog window */ private void createContents(final Shell shell) { FormLayout layout = new FormLayout(); layout.marginHeight = 5; layout.marginWidth = 5; shell.setLayout(layout); FormData data; eventDropDown = new Combo(shell, SWT.DROP_DOWN | SWT.BORDER); for (String event : getEventList()) { eventDropDown.add(event); } if (savedListener != null && savedListener.getEvent() != null) { eventDropDown.setText(savedListener.getEvent()); } else { eventDropDown.setText(getDefaultEvent()); } data = new FormData(); data.left = new FormAttachment(0, 120); data.right = new FormAttachment(100, 0); data.top = new FormAttachment(0, VSPACE); eventDropDown.setLayoutData(data); createLabel(shell, "Event", eventDropDown); Composite radioTypeComposite = new Composite(shell, SWT.NULL); radioTypeComposite.setBackground(shell.getBackground()); data = new FormData(); data.left = new FormAttachment(0, 120); data.right = new FormAttachment(100, 0); data.top = new FormAttachment(eventDropDown, VSPACE); radioTypeComposite.setLayoutData(data); radioTypeComposite.setLayout(new RowLayout()); classTypeButton = new Button(radioTypeComposite, SWT.RADIO); classTypeButton.setText("Java class"); classTypeButton.addSelectionListener( new SelectionListener() { @Override public void widgetSelected(SelectionEvent event) { enableClassType(); } @Override public void widgetDefaultSelected(SelectionEvent event) {} }); expressionTypeButton = new Button(radioTypeComposite, SWT.RADIO); expressionTypeButton.setText("Expression"); expressionTypeButton.addSelectionListener( new SelectionListener() { @Override public void widgetSelected(SelectionEvent event) { enableExpressionType(); } @Override public void widgetDefaultSelected(SelectionEvent event) {} }); delegateExpressionTypeButton = new Button(radioTypeComposite, SWT.RADIO); delegateExpressionTypeButton.setText("Delegate expression"); delegateExpressionTypeButton.addSelectionListener( new SelectionListener() { @Override public void widgetSelected(SelectionEvent event) { enableDelegateExpressionType(); } @Override public void widgetDefaultSelected(SelectionEvent event) {} }); if (PreferencesUtil.getBooleanPreference(Preferences.ALFRESCO_ENABLE)) { alfrescoExecutionTypeButton = new Button(radioTypeComposite, SWT.RADIO); alfrescoExecutionTypeButton.setText("Alfresco execution script"); alfrescoExecutionTypeButton.addSelectionListener( new SelectionListener() { @Override public void widgetSelected(SelectionEvent event) { enableAlfrescoType(false); } @Override public void widgetDefaultSelected(SelectionEvent event) {} }); alfrescoTaskTypeButton = new Button(radioTypeComposite, SWT.RADIO); alfrescoTaskTypeButton.setText("Alfresco task script"); alfrescoTaskTypeButton.addSelectionListener( new SelectionListener() { @Override public void widgetSelected(SelectionEvent event) { enableAlfrescoType(true); } @Override public void widgetDefaultSelected(SelectionEvent event) {} }); } createLabel(shell, "Type", radioTypeComposite); classNameText = new Text(shell, SWT.BORDER); if (savedListener != null && ImplementationType.IMPLEMENTATION_TYPE_CLASS.equals( savedListener.getImplementationType())) { classNameText.setText(savedListener.getImplementation()); } else { classNameText.setText(""); } data = new FormData(); data.left = new FormAttachment(0, 120); data.right = new FormAttachment(70, 0); data.top = new FormAttachment(radioTypeComposite, 10); classNameText.setEnabled(false); classNameText.setLayoutData(data); classSelectButton = new Button(shell, SWT.PUSH); classSelectButton.setText("Select class"); data = new FormData(); data.left = new FormAttachment(classNameText, 0); data.right = new FormAttachment(100, 0); data.top = new FormAttachment(classNameText, -4, SWT.TOP); classSelectButton.setLayoutData(data); classSelectButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent evt) { Shell shell = classNameText.getShell(); try { SelectionDialog dialog = JavaUI.createTypeDialog( shell, new ProgressMonitorDialog(shell), SearchEngine.createWorkspaceScope(), IJavaElementSearchConstants.CONSIDER_CLASSES, false); if (dialog.open() == SelectionDialog.OK) { Object[] result = dialog.getResult(); String className = ((IType) result[0]).getFullyQualifiedName(); if (className != null) { classNameText.setText(className); } } } catch (Exception ex) { ex.printStackTrace(); } } }); classSelectLabel = createLabel(shell, "Service class", expressionText); expressionText = new Text(shell, SWT.BORDER); if (savedListener != null && ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION.equals( savedListener.getImplementationType())) { expressionText.setText(savedListener.getImplementation()); } else { expressionText.setText(""); } data = new FormData(); data.left = new FormAttachment(0, 120); data.right = new FormAttachment(100, 0); data.top = new FormAttachment(radioTypeComposite, VSPACE); expressionText.setLayoutData(data); expressionLabel = createLabel(shell, "Expression", expressionText); delegateExpressionText = new Text(shell, SWT.BORDER); if (savedListener != null && ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION.equals( savedListener.getImplementationType())) { delegateExpressionText.setText(savedListener.getImplementation()); } else { delegateExpressionText.setText(""); } data = new FormData(); data.left = new FormAttachment(0, 120); data.right = new FormAttachment(100, 0); data.top = new FormAttachment(radioTypeComposite, VSPACE); delegateExpressionText.setLayoutData(data); delegateExpressionLabel = createLabel(shell, "Delegate expression", delegateExpressionText); scriptText = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL); data = new FormData(SWT.DEFAULT, 100); data.left = new FormAttachment(0, 120); data.right = new FormAttachment(100, 0); data.top = new FormAttachment(radioTypeComposite, VSPACE); scriptText.setLayoutData(data); scriptLabel = createLabel(shell, "Script", scriptText); runAsText = new Text(shell, SWT.BORDER); data = new FormData(); data.left = new FormAttachment(0, 120); data.right = new FormAttachment(100, 0); data.top = new FormAttachment(scriptText, VSPACE); runAsText.setLayoutData(data); runAsLabel = createLabel(shell, "Run as", runAsText); scriptProcessorText = new Text(shell, SWT.BORDER); data = new FormData(); data.left = new FormAttachment(0, 120); data.right = new FormAttachment(100, 0); data.top = new FormAttachment(runAsText, VSPACE); scriptProcessorText.setLayoutData(data); scriptProcessorLabel = createLabel(shell, "Script processor", scriptProcessorText); if (savedListener != null && (AlfrescoUserTask.ALFRESCO_SCRIPT_TASK_LISTENER.equalsIgnoreCase( savedListener.getImplementation()) || AlfrescoScriptTask.ALFRESCO_SCRIPT_EXECUTION_LISTENER.equalsIgnoreCase( savedListener.getImplementation()))) { List<FieldExtension> extensionList = savedListener.getFieldExtensions(); String script = ""; String runAs = ""; String scriptProcessor = ""; for (FieldExtension fieldExtension : extensionList) { if ("script".equalsIgnoreCase(fieldExtension.getFieldName())) { if (StringUtils.isNotEmpty(fieldExtension.getStringValue())) { script = fieldExtension.getStringValue(); } } else if ("runAs".equalsIgnoreCase(fieldExtension.getFieldName())) { if (StringUtils.isNotEmpty(fieldExtension.getStringValue())) { runAs = fieldExtension.getStringValue(); } } else if ("scriptProcessor".equalsIgnoreCase(fieldExtension.getFieldName())) { if (StringUtils.isNotEmpty(fieldExtension.getStringValue())) { scriptProcessor = fieldExtension.getStringValue(); } } } scriptText.setText(script); runAsText.setText(runAs); scriptProcessorText.setText(scriptProcessor); } else { scriptText.setText(""); runAsText.setText(""); scriptProcessorText.setText(""); } Composite extensionsComposite = new Composite(shell, SWT.WRAP); data = new FormData(); data.left = new FormAttachment(0, 120); data.right = new FormAttachment(100, 0); data.top = new FormAttachment(expressionText, 15); extensionsComposite.setLayoutData(data); GridLayout fieldLayout = new GridLayout(); fieldLayout.marginTop = 0; fieldLayout.numColumns = 1; extensionsComposite.setLayout(fieldLayout); fieldEditor = new FieldExtensionEditor("fieldEditor", extensionsComposite); fieldEditor .getLabelControl(extensionsComposite) .setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE)); if (savedListener != null && savedListener.getFieldExtensions() != null && savedListener.getFieldExtensions().size() > 0) { fieldEditor.initializeModel(savedListener.getFieldExtensions()); } extensionLabel = createLabel(shell, "Fields", extensionsComposite); // Create the cancel button and add a handler // so that pressing it will set input to null Button cancel = new Button(shell, SWT.PUSH); cancel.setText("Cancel"); data = new FormData(); data.left = new FormAttachment(0, 120); data.right = new FormAttachment(50, 0); data.top = new FormAttachment(extensionsComposite, 20); cancel.setLayoutData(data); cancel.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { shell.close(); } }); Button ok = new Button(shell, SWT.PUSH); ok.setText("OK"); data = new FormData(); data.left = new FormAttachment(0, 0); data.right = new FormAttachment(cancel, -HSPACE); data.top = new FormAttachment(cancel, 0, SWT.TOP); ok.setLayoutData(data); ok.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { if (ImplementationType.IMPLEMENTATION_TYPE_CLASS.equals(implementationType) && (StringUtils.isEmpty(classNameText.getText())) && AlfrescoUserTask.ALFRESCO_SCRIPT_TASK_LISTENER.equalsIgnoreCase(implementation) == false && AlfrescoScriptTask.ALFRESCO_SCRIPT_EXECUTION_LISTENER.equalsIgnoreCase( implementation) == false) { MessageDialog.openError(shell, "Validation error", "Class name must be filled."); return; } if (ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION.equals(implementationType) && (StringUtils.isEmpty(expressionText.getText()))) { MessageDialog.openError(shell, "Validation error", "Expression must be filled."); return; } if (ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION.equals(implementationType) && (StringUtils.isEmpty(delegateExpressionText.getText()))) { MessageDialog.openError( shell, "Validation error", "Delegate expression must be filled."); return; } eventName = eventDropDown.getText(); if (AlfrescoUserTask.ALFRESCO_SCRIPT_TASK_LISTENER.equalsIgnoreCase(implementation) || AlfrescoScriptTask.ALFRESCO_SCRIPT_EXECUTION_LISTENER.equalsIgnoreCase( implementation)) { script = scriptText.getText(); runAs = runAsText.getText(); scriptProcessor = scriptProcessorText.getText(); } else if (ImplementationType.IMPLEMENTATION_TYPE_CLASS.equals(implementationType)) { implementation = classNameText.getText(); } else if (ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION.equals( implementationType)) { implementation = expressionText.getText(); } else { implementation = delegateExpressionText.getText(); } fieldExtensionList = new ArrayList<FieldExtension>(); if (fieldEditor.getItems() != null) { for (TableItem tableItem : fieldEditor.getItems()) { FieldExtension fieldModel = new FieldExtension(); fieldModel.setFieldName(tableItem.getText(0)); fieldModel.setStringValue(tableItem.getText(1)); fieldModel.setExpression(tableItem.getText(2)); fieldExtensionList.add(fieldModel); } } shell.close(); } }); // Set the OK button as the default, so // user can type input and press Enter // to dismiss shell.setDefaultButton(ok); if (savedListener == null || savedListener.getImplementationType() == null) { classTypeButton.setSelection(true); enableClassType(); } else if (PreferencesUtil.getBooleanPreference(Preferences.ALFRESCO_ENABLE) && AlfrescoUserTask.ALFRESCO_SCRIPT_TASK_LISTENER.equalsIgnoreCase( savedListener.getImplementation())) { alfrescoTaskTypeButton.setSelection(true); enableAlfrescoType(true); } else if (PreferencesUtil.getBooleanPreference(Preferences.ALFRESCO_ENABLE) && AlfrescoScriptTask.ALFRESCO_SCRIPT_EXECUTION_LISTENER.equalsIgnoreCase( savedListener.getImplementation())) { alfrescoExecutionTypeButton.setSelection(true); enableAlfrescoType(false); } else if (ImplementationType.IMPLEMENTATION_TYPE_CLASS.equals( savedListener.getImplementationType())) { classTypeButton.setSelection(true); enableClassType(); } else if (ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION.equals( savedListener.getImplementationType())) { expressionTypeButton.setSelection(true); enableExpressionType(); } else { delegateExpressionTypeButton.setSelection(true); enableDelegateExpressionType(); } }