Example usage for org.eclipse.jface.action Action runWithEvent

List of usage examples for org.eclipse.jface.action Action runWithEvent

Introduction

In this page you can find the example usage for org.eclipse.jface.action Action runWithEvent.

Prototype

@Override
public void runWithEvent(Event event) 

Source Link

Document

The default implementation of this IAction method ignores the event argument, and simply calls run().

Usage

From source file:org.kalypso.ogc.gml.movie.controls.MovieComposite.java

License:Open Source License

/**
 * This function creates the button controls.
 * //from   w w  w . j  a va 2  s. c  o  m
 * @param parent
 *          The parent composite.
 * @return The button controls.
 */
public Composite createButtonControls(final Composite parent) {
    /* Get the image provider. */
    final IMovieImageProvider imageProvider = m_player.getImageProvider();

    /* Get the movie controls. */
    final IMovieControls movieControls = imageProvider.getMovieControls();

    /* Get the actions. */
    final Action[] actions = movieControls.getActions(m_player);

    /* Create a composite. */
    final Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(actions.length, false));

    /* Create the buttons. */
    for (final Action action : actions) {
        /* Create the image. */
        final Image image = action.getImageDescriptor().createImage();

        /* Create a button for the action. */
        final Button actionButton = new Button(composite, SWT.PUSH);
        actionButton.setImage(image);
        actionButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
        actionButton.setText(action.getText());
        actionButton.setToolTipText(action.getText());
        actionButton.addSelectionListener(new SelectionAdapter() {
            /**
             * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
             */
            @Override
            public void widgetSelected(final SelectionEvent e) {
                /* Get the source. */
                final Button source = (Button) e.getSource();

                /* Build the event. */
                final Event event = new Event();
                event.display = source.getDisplay();
                event.item = source;
                event.doit = true;

                /* Execute the action. */
                action.runWithEvent(event);
            }
        });

        actionButton.addDisposeListener(new DisposeListener() {
            /**
             * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
             */
            @Override
            public void widgetDisposed(final DisposeEvent e) {
                image.dispose();
            }
        });
    }

    return composite;
}

From source file:org.kalypso.ui.addlayer.internal.wms.ImportWmsWizardPage.java

License:Open Source License

@Override
public void createControl(final Composite parent) {
    m_binding = new DatabindingWizardPage(this, null);

    /* Create the main composite. */
    final Composite panel = new Composite(parent, SWT.NONE);
    panel.setLayout(new GridLayout(1, false));
    // panel.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );

    createAddressLine(panel).setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    /* Capabilities info */
    createCapabilitiesInfo(panel).setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    /* Create the section for the layer selection. */
    final Group layerGroup = new Group(panel, SWT.NONE);
    layerGroup.setLayout(new GridLayout(3, false));
    layerGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    layerGroup.setText(Messages.getString("org.kalypso.ui.wizard.wms.pages.ImportWmsWizardPage.7")); //$NON-NLS-1$

    /* The capabilities tree. */
    final TreeViewer capabilitiesTree = new TreeViewer(layerGroup,
            SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
    capabilitiesTree.setContentProvider(new WMSCapabilitiesContentProvider());
    capabilitiesTree.setLabelProvider(new WMSCapabilitiesLabelProvider());
    capabilitiesTree.setAutoExpandLevel(1);

    final GridData treeData = new GridData(SWT.FILL, SWT.FILL, true, true);
    treeData.widthHint = MIN_LIST_WIDTH;
    treeData.minimumWidth = MIN_LIST_WIDTH;
    treeData.minimumHeight = MIN_LIST_WIDTH;
    capabilitiesTree.getControl().setLayoutData(treeData);

    /* The layer button composite. */
    final GridData layerButtonData = new GridData(SWT.CENTER, SWT.FILL, false, true);
    layerButtonData.widthHint = 37;/*  w w  w. j  a  va2  s .  co m*/
    layerButtonData.minimumWidth = 37;

    final Composite buttonPanel = new Composite(layerGroup, SWT.NONE);
    buttonPanel.setLayout(new GridLayout(1, false));

    /* The layer viewer. */
    final ListViewer layerViewer = new ListViewer(layerGroup,
            SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
    layerViewer.setContentProvider(new ArrayContentProvider());
    layerViewer.setLabelProvider(new WMSCapabilitiesLabelProvider());

    final GridData layerViewerData = new GridData(SWT.FILL, SWT.FILL, true, true);
    layerViewerData.widthHint = MIN_LIST_WIDTH;
    layerViewerData.minimumWidth = MIN_LIST_WIDTH;
    layerViewerData.minimumHeight = MIN_LIST_WIDTH;
    layerViewer.getControl().setLayoutData(layerViewerData);
    layerViewer.setComparator(new ViewerComparator());

    /* The multi layer button. */
    createMultiLayerControl(layerGroup);

    /**
     * Actions
     */
    /* The layer button for adding a layer. */
    final IAction addAction = new AddLayerAction(capabilitiesTree, layerViewer, m_data);
    final Button layerButtonAdd = ActionButton.createButton(null, buttonPanel, addAction);
    layerButtonAdd.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));

    /* The layer button for removing a layer. */
    // FIXME
    final Action removeAction = new RemoveLayerAction(layerViewer, m_data);
    final Button layerButtonRemove = ActionButton.createButton(null, buttonPanel, removeAction);
    layerButtonRemove.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));

    /**
     * Binding
     */
    final IObservableValue targetInput = ViewersObservables.observeInput(capabilitiesTree);
    final IObservableValue modelInput = BeansObservables.observeValue(m_data,
            ICapabilitiesData.PROPERTY_CAPABILITIES);
    m_binding.bindValue(targetInput, modelInput);

    final IObservableSet chosenLayers = m_data.getChosenLayerSet();
    final IBeanValueProperty propertyValue = PojoProperties.value("title"); //$NON-NLS-1$
    ViewerSupport.bind(layerViewer, chosenLayers, propertyValue);

    /* The double click listener for the capabilities tree. */
    capabilitiesTree.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(final DoubleClickEvent event) {
            addAction.runWithEvent(null);
        }
    });

    layerViewer.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(final DoubleClickEvent event) {
            removeAction.runWithEvent(null);
        }
    });

    /* Set the control. */
    setControl(panel);
}