Example usage for org.eclipse.jface.resource JFaceResources getImage

List of usage examples for org.eclipse.jface.resource JFaceResources getImage

Introduction

In this page you can find the example usage for org.eclipse.jface.resource JFaceResources getImage.

Prototype

public static Image getImage(String key) 

Source Link

Document

Returns the image in JFace's image registry with the given key, or null if none.

Usage

From source file:org.modelio.core.ui.dialog.ModelioDialog.java

License:Open Source License

@objid("004a0aba-4a05-1fe0-bf4c-001ec947cd2a")
private Control createTitleArea(Composite parent) {
    this.titleArea = new Composite(parent, SWT.NONE);
    initializeDialogUnits(this.titleArea);
    FormData titleAreaData = new FormData();
    titleAreaData.top = new FormAttachment(0, 0);
    titleAreaData.left = new FormAttachment(0, 0);
    titleAreaData.right = new FormAttachment(100, 0);
    this.titleArea.setLayoutData(titleAreaData);
    FormLayout layout = new FormLayout();
    this.titleArea.setLayout(layout);
    this.titleArea.addDisposeListener(new DisposeListener() {
        @Override//from   w  ww . j  a v  a  2s . c  o m
        public void widgetDisposed(DisposeEvent e) {
            if (ModelioDialog.this.titleAreaColor != null)
                ModelioDialog.this.titleAreaColor.dispose();
        }
    });

    org.eclipse.swt.widgets.Display display = this.titleArea.getDisplay();
    Color background;
    Color foreground;
    if (this.titleAreaRGB != null) {
        this.titleAreaColor = new Color(display, this.titleAreaRGB);
        background = this.titleAreaColor;
        foreground = null;
    } else {
        background = JFaceColors.getBannerBackground(display);
        foreground = JFaceColors.getBannerForeground(display);
    }
    int verticalSpacing = convertVerticalDLUsToPixels(1);
    int horizontalSpacing = convertHorizontalDLUsToPixels(4);
    this.titleArea.setBackground(background);

    this.titleRightImageLabel = new Label(this.titleArea, SWT.NONE);
    this.titleRightImageLabel.setBackground(background);
    if (this.titleRightImage != null && !this.titleRightImage.isDisposed())
        this.titleRightImageLabel.setImage(this.titleRightImage);

    this.titleLeftImageLabel = new Label(this.titleArea, SWT.NONE);
    this.titleLeftImageLabel.setBackground(background);
    if (this.titleLeftImage == null || this.titleLeftImage.isDisposed())
        this.titleLeftImageLabel.setImage(JFaceResources.getImage(DLG_IMG_TITLE_BANNER));
    else
        this.titleLeftImageLabel.setImage(this.titleLeftImage);

    FormData rightImageData = new FormData();
    rightImageData.top = new FormAttachment(0, 0);
    rightImageData.right = new FormAttachment(100, 0);
    this.titleRightImageLabel.setLayoutData(rightImageData);

    FormData leftImageData = new FormData();
    leftImageData.top = new FormAttachment(0, 0);
    leftImageData.left = new FormAttachment(0, 0);
    this.titleLeftImageLabel.setLayoutData(leftImageData);

    this.titleLabel = new Label(this.titleArea, SWT.NONE);
    JFaceColors.setColors(this.titleLabel, foreground, background);
    this.titleLabel.setFont(JFaceResources.getBannerFont());
    this.titleLabel.setText(" ");
    FormData titleData = new FormData();
    titleData.left = new FormAttachment(this.titleLeftImageLabel, 5);
    titleData.top = new FormAttachment(0, verticalSpacing);
    titleData.right = new FormAttachment(this.titleRightImageLabel, -5);
    this.titleLabel.setLayoutData(titleData);
    this.messageImageLabel = new Label(this.titleArea, SWT.NONE);
    this.messageImageLabel.setBackground(background);
    this.messageLabel = new Text(this.titleArea, SWT.READ_ONLY | SWT.MULTI | SWT.WRAP);
    //this.messageLabel.setEnabled(false);
    this.messageLabel.setEditable(false);
    JFaceColors.setColors(this.messageLabel, foreground, background);
    this.messageLabel.setFont(JFaceResources.getDialogFont());
    this.messageLabelHeight = this.messageLabel.computeSize(-1, -1).y;
    this.leftFillerLabel = new Label(this.titleArea, SWT.NONE);
    this.leftFillerLabel.setBackground(background);
    setLayoutsForNormalMessage(verticalSpacing, horizontalSpacing);
    determineTitleImageLargest();
    return this.titleArea;
}

From source file:org.modelio.core.ui.dialog.ModelioDialog.java

License:Open Source License

@objid("004abae6-4a05-1fe0-bf4c-001ec947cd2a")
protected void setMessage(String newMessage, int newType) {
    Image newImage = null;/* w w  w.j  a  v a 2 s  .co m*/
    if (newMessage != null)
        switch (newType) {
        case 1: // '\001'
            newImage = JFaceResources.getImage("dialog_messasge_info_image");
            break;

        case 2: // '\002'
            newImage = JFaceResources.getImage("dialog_messasge_warning_image");
            break;

        case 3: // '\003'
            newImage = JFaceResources.getImage("dialog_message_error_image");
            break;
        }
    if (newType == 2) {
        setWarningMessage(newMessage);
    } else {
        setWarningMessage(null);
        showMessage(newMessage, newImage);
    }
}

From source file:org.modelio.xmi.gui.report.ReportDialog.java

License:Open Source License

@objid("b6e6dc8a-9020-4a2c-a6d0-907846478361")
@Override/*  w w  w . jav  a  2  s.  c  om*/
public Control createContentArea(Composite parent) {
    this.warningImage = JFaceResources.getImage("dialog_messasge_warning_image"); //$NON-NLS-1$
    this.errorImage = JFaceResources.getImage("dialog_message_error_image"); //$NON-NLS-1$
    this.infoImage = JFaceResources.getImage("dialog_messasge_info_image"); //$NON-NLS-1$

    Point s = getInitialSize();

    this.table = new Table(parent, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
    this.table.setLayoutData(data);
    this.table.setLinesVisible(true);

    TableColumn column = new TableColumn(this.table, SWT.NONE);
    column.setText("Message");

    updateViewFromModel();

    column.setWidth(s.x);

    this.table.addMouseListener(new MouseListener() {
        @Override
        public void mouseDoubleClick(MouseEvent e) {
            TableItem item = ReportDialog.this.table.getItem(new Point(e.x, e.y));
            if (item != null) {
                if (item.getData() instanceof ElementMessage) {
                    ElementMessage theElement = (ElementMessage) item.getData();

                    String desc = theElement.description;
                    ReportDialog.this.descriptionText.setText(desc);

                    // On a double clic, select the element
                    if (theElement.element != null && theElement.element.isValid()) {
                        ReportDialog.this.navigationService.fireNavigate(theElement.element);
                    }
                }
            }
        }

        @Override
        public void mouseDown(MouseEvent e) {
            // Nothing to do
        }

        @Override
        public void mouseUp(MouseEvent e) {
            TableItem item = ReportDialog.this.table.getItem(new Point(e.x, e.y));
            if (item != null) {
                if (item.getData() instanceof ElementMessage) {
                    ElementMessage theElement = (ElementMessage) item.getData();

                    String desc = theElement.description;
                    ReportDialog.this.descriptionText.setText(desc);

                    // On a CTRL + clic, select the element
                    if ((e.stateMask & SWT.CTRL) != 0) {
                        if (theElement.element != null && theElement.element.isValid()) {
                            ReportDialog.this.navigationService.fireNavigate(theElement.element);
                        }
                    }
                }
            }
        }
    });

    this.descriptionText = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.WRAP);
    GridData data_description = new GridData(SWT.FILL, SWT.FILL, true, false);
    data_description.heightHint = 50;
    this.descriptionText.setLayoutData(data_description);
    this.descriptionText.setBackground(UIColor.TEXT_READONLY_BG);
    return parent;
}

From source file:org.ow2.petals.client.swt.ClientApplication.java

License:Open Source License

@Override
protected void configureShell(Shell shell) {
    super.configureShell(shell);

    // Shell properties
    shell.setText("Petals Client");
    shell.setBounds(Display.getCurrent().getBounds());
    shell.setImages(new Image[] { JFaceResources.getImage(ImageIds.PETALS_16x16),
            JFaceResources.getImage(ImageIds.PETALS_32x32), JFaceResources.getImage(ImageIds.PETALS_48x48) });

    // Add tray support
    // TODO://w  ww. ja va2  s. co  m
}

From source file:org.ow2.petals.client.swt.dialogs.AboutDialog.java

License:Open Source License

/**
 * Constructor./*  ww w.j  a  v  a 2  s .c  o  m*/
 * @param parentShell
 */
public AboutDialog(Shell parentShell) {
    super(parentShell);
    setShellStyle(SWT.SHELL_TRIM);
    this.petalsImg = JFaceResources.getImage(ImageIds.PETALS_SPLASH);
}

From source file:org.ow2.petals.client.swt.tabs.HistoryTab.java

License:Open Source License

/**
 * Constructor./* www  . java2  s .  c  o  m*/
 * @param parent
 * @param clientApp
 */
public HistoryTab(Composite parent, final ClientApplication clientApp) {

    // Root elements
    super(parent, SWT.NONE);
    setLayout(new GridLayout());
    setLayoutData(new GridData(GridData.FILL_BOTH));

    SashForm sashForm = new SashForm(this, SWT.VERTICAL);
    sashForm.setLayoutData(new GridData(GridData.FILL_BOTH));
    sashForm.setSashWidth(5);

    // Create the bold font
    FontData[] fd = getFont().getFontData();
    fd = SwtUtils.getModifiedFontData(fd, SWT.BOLD);
    this.boldFont = new Font(getDisplay(), fd);

    // The header, with the search bar
    Composite container = new Composite(sashForm, SWT.NONE);
    container.setLayout(new GridLayout());
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    Composite subContainer = new Composite(container, SWT.NONE);
    GridLayoutFactory.swtDefaults().margins(0, 0).numColumns(3).applyTo(subContainer);
    subContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    new Label(subContainer, SWT.NONE).setText("The Requests that were previously sent to Petals Services.");
    final Text searchText = new Text(subContainer, SWT.SINGLE | SWT.BORDER);
    searchText.setText(SEARCH_TEXT);
    GridDataFactory.swtDefaults().grab(true, false).align(SWT.END, SWT.CENTER).hint(200, SWT.DEFAULT)
            .applyTo(searchText);

    Label l = new Label(subContainer, SWT.NONE);
    l.setImage(JFaceResources.getImage(ImageIds.SEARCH_16x16));
    GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER).applyTo(l);

    // The history viewer
    this.historyViewer = new TreeViewer(container, SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE);
    this.historyViewer.setContentProvider(new HistoryContentProvider());

    // Columns
    TreeViewerColumn column = new TreeViewerColumn(this.historyViewer, SWT.BEGINNING);
    column.getColumn().setText("Interface Name");
    column.setLabelProvider(new HistoryFirstColumnLabelProvider(0, this.boldFont));

    column = new TreeViewerColumn(this.historyViewer, SWT.CENTER);
    column.getColumn().setText("Service Name");
    column.setLabelProvider(new HistoryFirstColumnLabelProvider(1, this.boldFont));

    column = new TreeViewerColumn(this.historyViewer, SWT.CENTER);
    column.getColumn().setText("End-point Name");
    column.setLabelProvider(new HistoryFirstColumnLabelProvider(2, this.boldFont));

    column = new TreeViewerColumn(this.historyViewer, SWT.CENTER);
    column.getColumn().setText("Time");
    column.setLabelProvider(new HistorySecondColumnLabelProvider());

    // Remaining properties
    final HistoryViewerFilter historyViewerFilter = new HistoryViewerFilter();
    this.historyViewer.addFilter(historyViewerFilter);
    this.historyViewer.setInput(PreferencesManager.INSTANCE.getHistoryDirectory());
    this.historyViewer.expandAll();

    this.historyViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
    this.historyViewer.getTree().setHeaderVisible(true);
    this.historyViewer.getTree().setLinesVisible(true);

    TableLayout layout = new TableLayout();
    layout.addColumnData(new ColumnWeightData(30, 75, true));
    layout.addColumnData(new ColumnWeightData(30, 75, true));
    layout.addColumnData(new ColumnWeightData(30, 75, true));
    layout.addColumnData(new ColumnWeightData(10, 75, true));
    this.historyViewer.getTree().setLayout(layout);

    Link clearHistoryLink = new Link(container, SWT.NONE);
    clearHistoryLink.setText("<a>Clear All the History</a>");
    clearHistoryLink.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false));
    clearHistoryLink.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDown(MouseEvent e) {
            SwtUtils.clearHistoryWithProgressBar(getShell(), -1, clientApp);
            refreshHistory();
        }
    });

    // The preview part
    container = new Composite(sashForm, SWT.NONE);
    GridLayoutFactory.swtDefaults().spacing(15, 5).equalWidth(true).numColumns(2).applyTo(container);
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    new Label(container, SWT.NONE).setText("Quick Overview of the XML Payload");
    new Label(container, SWT.NONE).setText("The Request Properties");
    final StyledText xmlPayloadStyledText = SwtUtils.createXmlViewer(container, clientApp.getColorManager(),
            true);

    subContainer = new Composite(container, SWT.NONE);
    GridLayoutFactory.swtDefaults().margins(0, 0).numColumns(2).applyTo(subContainer);
    subContainer.setLayoutData(new GridData(GridData.FILL_BOTH));

    Label sepLabel = new Label(subContainer, SWT.HORIZONTAL | SWT.SEPARATOR);
    GridDataFactory.fillDefaults().span(2, 1).applyTo(sepLabel);

    new Label(subContainer, SWT.NONE).setText("Interface Name:");
    final Label itfNameLabel = new Label(subContainer, SWT.NONE);
    itfNameLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    new Label(subContainer, SWT.NONE).setText("Service Name:");
    final Label srvNameLabel = new Label(subContainer, SWT.NONE);
    srvNameLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    new Label(subContainer, SWT.NONE).setText("End-point Name:");
    final Label edptNameLabel = new Label(subContainer, SWT.NONE);
    edptNameLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    new Label(subContainer, SWT.NONE).setText("Operation Name:");
    final Label opNameLabel = new Label(subContainer, SWT.NONE);
    opNameLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    new Label(subContainer, SWT.NONE).setText("MEP:");
    final Label mepLabel = new Label(subContainer, SWT.NONE);
    mepLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    new Label(subContainer, SWT.NONE).setText("Properties Count:");
    final Label propsCountLabel = new Label(subContainer, SWT.NONE);
    propsCountLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    new Label(subContainer, SWT.NONE).setText("Attachments Count:");
    final Label attCountLabel = new Label(subContainer, SWT.NONE);
    attCountLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    new Label(subContainer, SWT.NONE).setText("Sent On:");
    final Label dateLabel = new Label(subContainer, SWT.NONE);
    dateLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    final Button loadButton = new Button(subContainer, SWT.PUSH);
    loadButton.setText("Load this Request");
    loadButton.setVisible(false);
    GridDataFactory.swtDefaults().span(2, 1).indent(0, 10).grab(true, false).align(SWT.FILL, SWT.CENTER)
            .applyTo(loadButton);
    loadButton.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event e) {
            clientApp.displayRequest(HistoryTab.this.shownRequest);
        }
    });

    // Define the sash weights
    sashForm.setWeights(new int[] { 50, 50 });

    // Add the listeners
    this.historyViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent e) {

            Object o = ((IStructuredSelection) e.getSelection()).getFirstElement();
            String date = null;
            RequestMessageBean req = null;
            if (o instanceof File) {
                try {
                    InputStream is = new FileInputStream((File) o);
                    Properties props = new Properties();
                    props.load(is);

                    req = RequestMessageBeanUtils.read(props);
                    date = HistoryFirstColumnLabelProvider.formatDateStr(((File) o).lastModified(), true);

                } catch (Exception e1) {
                    clientApp.log("Error while reading a history entry.", e1, Level.INFO);

                } finally {
                    HistoryTab.this.shownRequest = req;
                    loadButton.setEnabled(HistoryTab.this.shownRequest != null);
                }
            }

            if (req != null) {
                loadButton.setVisible(true);
                xmlPayloadStyledText.setText(req.getXmlPayload() != null ? req.getXmlPayload() : "");
                itfNameLabel.setText(req.getInterfaceName().getLocalPart() + " - "
                        + req.getInterfaceName().getNamespaceURI());
                edptNameLabel.setText(Utils.isEmptyString(req.getEndpointName()) ? "-" : req.getEndpointName());
                if (req.getServiceName() != null)
                    srvNameLabel.setText(req.getServiceName().getLocalPart() + " - "
                            + req.getServiceName().getNamespaceURI());
                else
                    srvNameLabel.setText("-");

                mepLabel.setText(req.getMep() != null ? req.getMep().toString() : "-");
                dateLabel.setText(date != null ? date : "-");
                propsCountLabel
                        .setText(String.valueOf(req.getProperties() != null ? req.getProperties().size() : 0));
                attCountLabel.setText(
                        String.valueOf(req.getAttachments() != null ? req.getAttachments().size() : 0));
                if (req.getOperation() != null)
                    opNameLabel.setText(
                            req.getOperation().getLocalPart() + " - " + req.getOperation().getNamespaceURI());
                else
                    opNameLabel.setText("-");

            } else {
                xmlPayloadStyledText.setText("");
                itfNameLabel.setText("");
                srvNameLabel.setText("");
                edptNameLabel.setText("");
                opNameLabel.setText("");
                mepLabel.setText("");
                propsCountLabel.setText("");
                attCountLabel.setText("");
                dateLabel.setText("");
                loadButton.setVisible(false);
            }
        }
    });

    searchText.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDown(MouseEvent e) {
            searchText.selectAll();
        }
    });

    searchText.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {

            String txt = searchText.getText().trim();
            if (txt.length() == 0) {
                searchText.setText(SEARCH_TEXT);
            } else {
                historyViewerFilter.setSearchText(SEARCH_TEXT.equals(txt) ? null : txt);
                HistoryTab.this.historyViewer.refresh();
            }
        }
    });

    searchText.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {

            Text text = (Text) e.widget;
            if (text.getText().equals(SEARCH_TEXT)) {
                e.doit = false;
                text.setText(String.valueOf(e.character));
                text.setSelection(1);
            }
        }
    });
}

From source file:org.ow2.petals.client.swt.tabs.MessageComposite.java

License:Open Source License

/**
 * Creates the section for the pay-load.
 *//*w  w  w.  j a v  a2s  .  c  om*/
private void createPayloadSection() {

    // Container
    Composite container = new Composite(this, SWT.NONE);
    GridLayoutFactory.swtDefaults().spacing(5, 0).margins(0, 0).applyTo(container);
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    Composite subContainer = new Composite(container, SWT.NONE);
    GridLayoutFactory.swtDefaults().numColumns(2).margins(0, 0).extendedMargins(0, 5, 0, 0)
            .applyTo(subContainer);
    subContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Menu + Label
    final ToolBar toolBar = new ToolBar(subContainer, SWT.FLAT);
    new Label(subContainer, SWT.NONE).setText(this.title + " - XML Payload");

    // XML Viewer
    this.styledText = SwtUtils.createXmlViewer(container, this.clientApp.getColorManager(), false);

    // Link the menu and the tool-bar
    this.menu = new Menu(getShell(), SWT.POP_UP);
    final ToolItem item = new ToolItem(toolBar, SWT.FLAT);
    item.setImage(JFaceResources.getImage(ImageIds.VIEW_MENU_16x16));
    item.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event e) {

            Rectangle rect = item.getBounds();
            Point pt = new Point(rect.x, rect.y + rect.height);
            pt = toolBar.toDisplay(pt);
            MessageComposite.this.menu.setLocation(pt.x, pt.y);
            MessageComposite.this.menu.setVisible(true);
        }
    });
}

From source file:org.ow2.petals.client.swt.tabs.MessageComposite.java

License:Open Source License

/**
 * Creates the section for the message properties.
 *///w  w  w.  j  ava  2 s. c  o m
private void createPropertiesSection() {

    // The container
    Composite container = new Composite(this, SWT.NONE);
    container.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayoutFactory.swtDefaults().numColumns(2).margins(0, 0).applyTo(container);

    Composite subContainer = new Composite(container, SWT.NONE);
    GridLayoutFactory.swtDefaults().numColumns(2).margins(0, 0).extendedMargins(0, 5, 0, 0)
            .applyTo(subContainer);
    GridDataFactory.swtDefaults().span(2, 1).grab(true, false).align(SWT.FILL, SWT.CENTER)
            .applyTo(subContainer);

    // Menu + Label
    final ToolBar toolBar = new ToolBar(subContainer, SWT.FLAT);
    new Label(subContainer, SWT.NONE).setText("Message Properties");

    // The properties
    this.propertiesViewer = createPropertiesViewer(container);
    this.propertiesViewer.setInput(this.properties);

    // The buttons
    Composite buttonsComposite = new Composite(container, SWT.NONE);
    GridLayoutFactory.swtDefaults().margins(0, 0).applyTo(buttonsComposite);
    buttonsComposite.setLayoutData(new GridData(SWT.DEFAULT, SWT.BEGINNING, false, false));

    Button b = new Button(buttonsComposite, SWT.PUSH);
    b.setText("Add...");
    b.setToolTipText("Add a new message property");
    b.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
    b.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {

            KeyValueDialog dlg = new KeyValueDialog(getShell(), MessageComposite.this.properties);
            if (dlg.open() == Window.OK) {
                MessageComposite.this.properties.put(dlg.getKey(), dlg.getValue());
                MessageComposite.this.propertiesViewer.refresh();
            }
        }
    });

    b = new Button(buttonsComposite, SWT.PUSH);
    b.setText("Remove");
    b.setToolTipText("Remove the selected message property");
    b.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
    b.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {

            ISelection s = MessageComposite.this.propertiesViewer.getSelection();
            for (Iterator<?> it = ((IStructuredSelection) s).iterator(); it.hasNext();) {
                String key = (String) ((Map.Entry<?, ?>) it.next()).getKey();
                MessageComposite.this.properties.remove(key);
            }

            MessageComposite.this.propertiesViewer.refresh();
        }
    });

    // Link the menu and the tool-bar
    final Menu localMenu = new Menu(getShell(), SWT.POP_UP);
    final ToolItem item = new ToolItem(toolBar, SWT.FLAT);
    item.setImage(JFaceResources.getImage(ImageIds.VIEW_MENU_16x16));
    item.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event e) {

            Rectangle rect = item.getBounds();
            Point pt = new Point(rect.x, rect.y + rect.height);
            pt = toolBar.toDisplay(pt);
            localMenu.setLocation(pt.x, pt.y);
            localMenu.setVisible(true);
        }
    });

    MenuItem menuItem = new MenuItem(localMenu, SWT.PUSH);
    menuItem.setText("Clear All the Properties");
    menuItem.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event e) {
            MessageComposite.this.properties.clear();
            MessageComposite.this.propertiesViewer.refresh();
        }
    });
}

From source file:org.ow2.petals.client.swt.tabs.MessageComposite.java

License:Open Source License

/**
 * Creates the section for the message attachments.
 *//*  w  w w.j a  v  a 2  s  .c  om*/
private void createAttachmentsSection() {

    // The container
    Composite container = new Composite(this, SWT.NONE);
    container.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayoutFactory.swtDefaults().numColumns(2).margins(0, 0).applyTo(container);

    Composite subContainer = new Composite(container, SWT.NONE);
    GridLayoutFactory.swtDefaults().numColumns(2).margins(0, 0).extendedMargins(0, 5, 0, 0)
            .applyTo(subContainer);
    GridDataFactory.swtDefaults().span(2, 1).grab(true, false).align(SWT.FILL, SWT.CENTER)
            .applyTo(subContainer);

    // Menu + Label
    final ToolBar toolBar = new ToolBar(subContainer, SWT.FLAT);
    new Label(subContainer, SWT.NONE).setText("File Attachments");

    // The attachments
    this.attachmentsViewer = createAttachmentsViewer(container);
    this.attachmentsViewer.setInput(this.attachments);

    // The buttons
    Composite buttonsComposite = new Composite(container, SWT.NONE);
    GridLayoutFactory.swtDefaults().margins(0, 0).applyTo(buttonsComposite);
    buttonsComposite.setLayoutData(new GridData(SWT.DEFAULT, SWT.BEGINNING, false, false));

    Button b = new Button(buttonsComposite, SWT.PUSH);
    b.setText("Add...");
    b.setToolTipText("Add a new message property");
    b.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
    b.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {

            FileDialog dlg = new FileDialog(getShell(), SWT.MULTI);
            if (dlg.open() != null) {
                for (String s : dlg.getFileNames())
                    MessageComposite.this.attachments.add(new File(dlg.getFilterPath(), s));

                MessageComposite.this.attachmentsViewer.refresh();
                MessageComposite.this.clientApp.validateRequest();
            }
        }
    });

    b = new Button(buttonsComposite, SWT.PUSH);
    b.setText("Remove");
    b.setToolTipText("Remove the selected message property");
    b.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
    b.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {

            ISelection s = MessageComposite.this.attachmentsViewer.getSelection();
            for (Iterator<?> it = ((IStructuredSelection) s).iterator(); it.hasNext();)
                MessageComposite.this.attachments.remove(it.next());

            MessageComposite.this.attachmentsViewer.refresh();
            MessageComposite.this.clientApp.validateRequest();
        }
    });

    // Link the menu and the tool-bar
    final Menu localMenu = new Menu(getShell(), SWT.POP_UP);
    final ToolItem item = new ToolItem(toolBar, SWT.FLAT);
    item.setImage(JFaceResources.getImage(ImageIds.VIEW_MENU_16x16));
    item.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event e) {

            Rectangle rect = item.getBounds();
            Point pt = new Point(rect.x, rect.y + rect.height);
            pt = toolBar.toDisplay(pt);
            localMenu.setLocation(pt.x, pt.y);
            localMenu.setVisible(true);
        }
    });

    MenuItem menuItem = new MenuItem(localMenu, SWT.PUSH);
    menuItem.setText("Remove All the Attachments");
    menuItem.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event e) {
            MessageComposite.this.attachments.clear();
            MessageComposite.this.attachmentsViewer.refresh();
        }
    });
}

From source file:org.ow2.petals.client.swt.tabs.RequestTab.java

License:Open Source License

/**
 * Creates the section for the tools and reporting.
 *//*from w  w w . ja  v a 2 s .  c  om*/
private void createToolSection() {

    Group sendGroup = new Group(this, SWT.SHADOW_ETCHED_OUT);
    GridLayoutFactory.swtDefaults().numColumns(3).applyTo(sendGroup);
    GridDataFactory.swtDefaults().grab(true, false).align(SWT.FILL, SWT.END).indent(0, 8).applyTo(sendGroup);
    sendGroup.setText("Message Sending");

    // The "send "options
    Composite metaComposite = new Composite(sendGroup, SWT.NONE);
    GridLayoutFactory.swtDefaults().numColumns(2).margins(5, 3).spacing(5, 10).applyTo(metaComposite);

    Button syncButton = new Button(metaComposite, SWT.CHECK);
    GridDataFactory.swtDefaults().span(2, 1).applyTo(syncButton);
    syncButton.setText("Send Synchroneously");

    new Label(metaComposite, SWT.NONE).setText("Timeout:");
    this.timeoutSpinner = new Spinner(metaComposite, SWT.BORDER);
    int defaultTimeout = PreferencesManager.INSTANCE.getDefaultTimeout();
    this.timeoutSpinner.setValues(defaultTimeout, 0, Integer.MAX_VALUE, 0, 1000, 100);

    this.sendButton = new Button(sendGroup, SWT.PUSH);
    GridDataFactory.swtDefaults().grab(false, true).align(SWT.BEGINNING, SWT.FILL).applyTo(this.sendButton);
    this.sendButton.setText("Send  ");
    this.sendButton.setToolTipText("Send the Request to the Target Service");
    this.sendButton.setImage(JFaceResources.getImage(ImageIds.SEND_64x64));
    this.sendButton.setEnabled(false);

    // ... and to display reports
    Composite reportingComposite = new Composite(sendGroup, SWT.NONE);
    GridLayoutFactory.swtDefaults().margins(25, 8).applyTo(reportingComposite);
    GridDataFactory.fillDefaults().span(1, 2).grab(true, true).align(SWT.FILL, SWT.END)
            .applyTo(reportingComposite);

    // Use a sub-composite, to keep UI consistency when updating the messages (parent's layout())
    Composite subComposite = new Composite(reportingComposite, SWT.NONE);
    GridLayoutFactory.swtDefaults().margins(0, 0).numColumns(2).applyTo(subComposite);
    subComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    this.reportingImageLabel = new Label(subComposite, SWT.NONE);
    this.reportingStyledText = new StyledText(subComposite, SWT.MULTI);
    this.reportingStyledText.setLayoutData(new GridData(GridData.FILL_BOTH));

    this.reportingProgressBar = new ProgressBar(reportingComposite, SWT.INDETERMINATE);
    this.reportingProgressBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    this.reportingProgressBar.setVisible(false);

    // What to do when "send" is clicked?
    this.sendButton.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event e) {

            RequestMessageBean req = null;
            try {
                req = createRequestInstance();
                RequestTab.this.clientApp.getPetalsFacade().send(req);
                updateMessage("The request was successfully sent.", IStatus.INFO);

            } catch (Exception e1) {
                MessageDialog.openInformation(getShell(), "Error",
                        "An error occurred while sending a request to a Petals service.");
                RequestTab.this.clientApp.log("Error while sending a Petals message.", e1, Level.INFO);

            } finally {

                if (req != null) {
                    File f = Utils.getNewHistoryFile(req);
                    try {
                        Utils.saveRequest(f, req, false);
                        RequestTab.this.clientApp.refreshHistory();

                    } catch (IOException e1) {
                        RequestTab.this.clientApp.log("Error while updating the history.", e1, Level.INFO);
                    }
                }
            }
        }
    });
}