Example usage for org.eclipse.jface.action ToolBarManager createControl

List of usage examples for org.eclipse.jface.action ToolBarManager createControl

Introduction

In this page you can find the example usage for org.eclipse.jface.action ToolBarManager createControl.

Prototype

public ToolBar createControl(Composite parent) 

Source Link

Document

Creates and returns this manager's tool bar control.

Usage

From source file:ar.com.fluxit.jqa.wizard.page.LayersDefinitionWizardPage.java

License:Open Source License

private void createLayersGroup(SashForm sash) {
    final Group layersGroup = new Group(sash, SWT.NONE);
    final GridLayout layersGroupGridLayout = new GridLayout();
    layersGroupGridLayout.verticalSpacing = -1;
    layersGroup.setLayout(layersGroupGridLayout);
    layersGroup.setText("Layers");
    ViewForm viewForm = new ViewForm(layersGroup, SWT.FLAT | SWT.BORDER);
    viewForm.setLayout(layersGroupGridLayout);
    ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
    ToolBar toolBar = toolBarManager.createControl(viewForm);
    toolBar.setBackground(layersGroup.getBackground());
    viewForm.setTopLeft(toolBar);//from  w w w  .  ja  v a 2  s .  c om
    viewForm.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    TableViewer layersTable = new TableViewer(layersGroup,
            SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    layersTable.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    layersTable.setContentProvider(ArrayContentProvider.getInstance());
    layersTable.setInput(getWizard().getLayers());
    layersTable.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            Layer layer = (Layer) element;
            String result = layer.getName();
            if (!layer.getPackages().isEmpty()) {
                result += " (" + layer.getPackages().size() + ")";
            }
            return result;
        }
    });
    layersTable.setCellEditors(new CellEditor[] { new TextCellEditor(layersTable.getTable()) });
    layersTable.setCellModifier(new LayerCellModifier(layersTable));
    layersTable.setColumnProperties(new String[] { "layer" });
    toolBarManager.add(new NewLayerAction(getWizard().getLayers(), layersTable));
    final EditLayerAction editLayerAction = new EditLayerAction(layersTable);
    editLayerAction.setEnabled(false);
    toolBarManager.add(editLayerAction);
    final RemoveLayerAction removeLayerAction = new RemoveLayerAction(getWizard().getLayers(), layersTable,
            targetPackagesTable, getContainer());
    removeLayerAction.setEnabled(false);
    toolBarManager.add(removeLayerAction);
    toolBarManager.update(true);
    layersTable.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent paramSelectionChangedEvent) {
            layerSelectionChanged(paramSelectionChangedEvent.getSelection(), editLayerAction,
                    removeLayerAction);
        }
    });
    layersTable.addDropSupport(DND.DROP_MOVE, getTransferTypes(), new LayersListTableDropListener(layersTable,
            targetPackagesTable, getDragViewerHolder(), getDragInputHolder(), getContainer()));
}

From source file:at.medevit.elexis.inbox.ui.part.InboxView.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));

    Composite filterComposite = new Composite(composite, SWT.NONE);
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    filterComposite.setLayoutData(data);
    filterComposite.setLayout(new GridLayout(2, false));

    filterText = new Text(filterComposite, SWT.SEARCH);
    filterText.setMessage("Filter");
    data = new GridData(GridData.FILL_HORIZONTAL);
    filterText.setLayoutData(data);/*w  ww .  j  a  v a 2  s  .  c  om*/
    filterText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            if (filterText.getText().length() > 1) {
                filter.setSearchText(filterText.getText());
                viewer.refresh();
            } else {
                filter.setSearchText("");
                viewer.refresh();
            }
        }
    });

    ToolBarManager menuManager = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL | SWT.WRAP);
    menuManager.createControl(filterComposite);

    viewer = new CheckboxTreeViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    viewer.getControl().setLayoutData(gd);

    ViewerFilter[] filters = new ViewerFilter[1];
    filters[0] = filter;
    viewer.setFilters(filters);

    contentProvider = new InboxElementContentProvider();
    viewer.setContentProvider(contentProvider);

    viewer.setLabelProvider(new InboxElementLabelProvider());

    viewer.addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            if (event.getElement() instanceof PatientInboxElements) {
                PatientInboxElements patientInbox = (PatientInboxElements) event.getElement();
                for (InboxElement inboxElement : patientInbox.getElements()) {
                    if (!filter.isActive() || filter.isSelect(inboxElement)) {
                        State newState = toggleInboxElementState(inboxElement);
                        if (newState == State.NEW) {
                            viewer.setChecked(inboxElement, false);
                        } else {
                            viewer.setChecked(inboxElement, true);
                        }
                        contentProvider.refreshElement(inboxElement);
                    }
                }
                contentProvider.refreshElement(patientInbox);
            } else if (event.getElement() instanceof InboxElement) {
                InboxElement inboxElement = (InboxElement) event.getElement();
                if (!filter.isActive() || filter.isSelect(inboxElement)) {
                    toggleInboxElementState(inboxElement);
                    contentProvider.refreshElement(inboxElement);
                }
            }
            viewer.refresh(false);
        }
    });

    viewer.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(DoubleClickEvent event) {
            StructuredSelection selection = (StructuredSelection) viewer.getSelection();
            if (!selection.isEmpty()) {
                Object selectedObj = selection.getFirstElement();
                if (selectedObj instanceof InboxElement) {
                    InboxElementUiExtension extension = new InboxElementUiExtension();
                    extension.fireDoubleClicked((InboxElement) selectedObj);
                }
            }
        }
    });

    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (selection instanceof StructuredSelection && !selection.isEmpty()) {
                if (setAutoSelectPatient) {
                    Object selectedElement = ((StructuredSelection) selection).getFirstElement();
                    if (selectedElement instanceof InboxElement) {
                        ElexisEventDispatcher.fireSelectionEvent(((InboxElement) selectedElement).getPatient());
                    } else if (selectedElement instanceof PatientInboxElements) {
                        ElexisEventDispatcher
                                .fireSelectionEvent(((PatientInboxElements) selectedElement).getPatient());
                    }
                }
            }
        }
    });

    final Transfer[] dropTransferTypes = new Transfer[] { FileTransfer.getInstance() };
    viewer.addDropSupport(DND.DROP_COPY, dropTransferTypes, new DropTargetAdapter() {

        @Override
        public void dragEnter(DropTargetEvent event) {
            event.detail = DND.DROP_COPY;
        }

        @Override
        public void drop(DropTargetEvent event) {
            if (dropTransferTypes[0].isSupportedType(event.currentDataType)) {
                String[] files = (String[]) event.data;
                Patient patient = null;

                if (event.item != null) {
                    Object data = event.item.getData();
                    if (data instanceof InboxElement) {
                        patient = ((InboxElement) data).getPatient();
                    } else if (data instanceof PatientInboxElements) {
                        patient = ((PatientInboxElements) data).getPatient();
                    }
                }

                if (patient == null) {
                    // fallback
                    patient = ElexisEventDispatcher.getSelectedPatient();
                }
                if (patient != null) {
                    if (files != null) {
                        for (String file : files) {
                            try {
                                InboxServiceComponent.getService().createInboxElement(patient,
                                        ElexisEventDispatcher.getSelectedMandator(), file, true);
                            } catch (Exception e) {
                                LoggerFactory.getLogger(InboxView.class).warn("drop error", e);
                            }
                        }
                    }

                    viewer.refresh();
                } else {
                    MessageDialog.openWarning(Display.getCurrent().getActiveShell(), "Warnung",
                            "Bitte whlen Sie zuerst einen Patienten aus.");
                }

            }
        }

    });

    addFilterActions(menuManager);

    InboxServiceComponent.getService().addUpdateListener(new IInboxUpdateListener() {
        public void update(final InboxElement element) {
            Display.getDefault().asyncExec(new Runnable() {
                public void run() {
                    contentProvider.refreshElement(element);
                    viewer.refresh();
                }
            });
        }
    });

    reload();

    MenuManager ctxtMenuManager = new MenuManager();
    Menu menu = ctxtMenuManager.createContextMenu(viewer.getTree());
    viewer.getTree().setMenu(menu);
    getSite().registerContextMenu(ctxtMenuManager, viewer);

    ElexisEventDispatcher.getInstance().addListeners(mandantChanged);
    getSite().setSelectionProvider(viewer);

    setAutoSelectPatientState(CoreHub.userCfg.get(Preferences.INBOX_PATIENT_AUTOSELECT, false));
}

From source file:ch.elexis.core.ui.dialogs.SelectFallDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    Composite ret = new Composite(parent, SWT.None);
    ret.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    GridLayout gl_ret = new GridLayout(1, false);
    gl_ret.marginWidth = 0;/*  w w  w . j  a v a2  s  .  c o  m*/
    gl_ret.marginHeight = 0;
    ret.setLayout(gl_ret);

    list = new List(ret, SWT.BORDER);
    list.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));

    reloadFaelleList();

    ToolBarManager tbManager = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL | SWT.WRAP);
    tbManager.add(GlobalActions.neuerFallAction);
    tbManager.createControl(ret);

    ElexisEventDispatcher.getInstance().addListeners(updateFallListener);

    return ret;
}

From source file:ch.elexis.core.ui.dialogs.SelectFallNoObligationDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);

    Composite areaComposite = new Composite(composite, SWT.NONE);
    areaComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL));

    areaComposite.setLayout(new FormLayout());

    Label lbl = new Label(areaComposite, SWT.NONE);
    lbl.setText("Fall erstellen");

    ToolBarManager tbManager = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL | SWT.WRAP);
    tbManager.add(GlobalActions.neuerFallAction);
    ToolBar toolbar = tbManager.createControl(areaComposite);

    FormData fd = new FormData();
    fd.top = new FormAttachment(0, 5);
    fd.left = new FormAttachment(0, 5);
    lbl.setLayoutData(fd);/*  w  w w . j a v a  2  s . c  o m*/

    fd = new FormData();
    fd.top = new FormAttachment(0, 5);
    fd.left = new FormAttachment(30, 5);
    toolbar.setLayoutData(fd);

    lbl = new Label(areaComposite, SWT.NONE);
    lbl.setText("Fall auswhlen");

    noOblFallCombo = new ComboViewer(areaComposite);

    noOblFallCombo.setContentProvider(new ArrayContentProvider());

    noOblFallCombo.setInput(getNoObligationFaelle());
    noOblFallCombo.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((Fall) element).getLabel();
        }
    });

    if (lastSelectedFall != null)
        noOblFallCombo.setSelection(new StructuredSelection(lastSelectedFall));

    ElexisEventDispatcher.getInstance()
            .addListeners(new UpdateFallComboListener(noOblFallCombo, Fall.class, 0xff));

    fd = new FormData();
    fd.top = new FormAttachment(toolbar, 5);
    fd.left = new FormAttachment(0, 5);
    lbl.setLayoutData(fd);

    fd = new FormData();
    fd.top = new FormAttachment(toolbar, 5);
    fd.left = new FormAttachment(30, 5);
    fd.right = new FormAttachment(100, -5);
    noOblFallCombo.getControl().setLayoutData(fd);

    return areaComposite;
}

From source file:ch.medelexis.templator.ui.ProcessingSchemaDisplay.java

License:Open Source License

public ProcessingSchemaDisplay(Composite parent, ICallback handler) {
    super(parent, SWT.NONE);
    if (parent.getLayout() instanceof GridLayout) {
        setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    }// w ww  .j  ava  2  s .c om
    setLayout(new FillLayout());
    form = UiDesk.getToolkit().createScrolledForm(this);
    saveHandler = handler;
    Composite body = form.getBody();
    body.setLayout(new GridLayout());
    makeActions();
    ToolBarManager tbm = new ToolBarManager(SWT.HORIZONTAL);
    tbm.add(printAction);
    tbm.add(addAction);
    tbm.add(directOutputAction);
    tbm.createControl(body);

    Composite cButtons = new Composite(body, SWT.NONE);
    cButtons.setLayout(new GridLayout(3, false));
    cButtons.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
    new Label(cButtons, SWT.NONE).setText("Schablone");
    tTemplate = new Text(cButtons, SWT.BORDER);
    tTemplate.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
    Button bChoose = new Button(cButtons, SWT.PUSH);
    bChoose.setText("whlen");
    bChoose.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
            fd.setFilterPath(
                    CoreHub.localCfg.get(Preferences.PREF_TEMPLATEBASE, System.getProperty("user.home")));
            String fname = fd.open();
            if (fname != null) {
                File f = new File(fname);
                tTemplate.setText(f.getName());
            }
        }

    });
    new Label(cButtons, SWT.NONE).setText("Ausgabeprozessor");
    cbProcessor = new Combo(cButtons, SWT.SINGLE);
    cbProcessor.setLayoutData(SWTHelper.getFillGridData(2, true, 1, false));
    IProcessor[] processors = ProcessingSchema.getProcessors();
    for (IProcessor pro : processors) {
        cbProcessor.add(pro.getName());
    }
    cFields = new Composite(body, SWT.NONE);
    cFields.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    cFields.setLayout(new GridLayout(2, false));

}

From source file:cn.dockerfoundry.ide.eclipse.server.ui.internal.editor.ApplicationActionMenuControl.java

License:Open Source License

protected ToolBarManager createToolBarManager(Composite parent) {
    ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
    ToolBar toolBar = toolBarManager.createControl(parent);

    // Adapt it to a form if a form tool kit is specified
    adaptControl(toolBar);/*from www. j a  va2 s. c o m*/

    GridDataFactory.fillDefaults().grab(false, false).align(SWT.BEGINNING, SWT.BEGINNING).applyTo(toolBar);
    return toolBarManager;
}

From source file:cn.dockerfoundry.ide.eclipse.server.ui.internal.editor.ApplicationMasterPart.java

License:Open Source License

private void createApplicationsSection() {
    Section section = getSection();/*  www  .j av  a 2  s. c om*/
    section.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(section);
    section.setText(Messages.COMMONTXT_APPLICATIONS);
    section.setDescription(Messages.ApplicationMasterPart_TEXT_APP_DESCRIP);

    Composite client = toolkit.createComposite(section);
    client.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(client);
    section.setClient(client);

    Composite headerComposite = toolkit.createComposite(section, SWT.NONE);
    RowLayout rowLayout = new RowLayout();
    rowLayout.marginTop = 0;
    rowLayout.marginBottom = 0;
    headerComposite.setLayout(rowLayout);
    headerComposite.setBackground(null);

    ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
    toolBarManager.createControl(headerComposite);

    applicationsViewer = new TableViewer(toolkit.createTable(client, SWT.NONE));
    applicationsViewer.setContentProvider(new TreeContentProvider());
    applicationsViewer.setLabelProvider(new ServerLabelProvider() {
        @Override
        public Image getImage(Object element) {
            Image image = super.getImage(element);

            if (element instanceof IModule) {
                IModule module = (IModule) element;
                DockerFoundryApplicationModule appModule = editorPage.getCloudServer()
                        .getExistingCloudModule(module);
                if (appModule != null && appModule.getErrorMessage() != null) {
                    return DockerFoundryImages.getImage(new DecorationOverlayIcon(image,
                            DockerFoundryImages.OVERLAY_ERROR, IDecoration.BOTTOM_LEFT));
                }
            }

            return image;
        }

        @Override
        public String getText(Object element) {
            // This is the WTP module name (usually, it's the workspace
            // project name)
            String moduleName = super.getText(element);

            // However, the user has the option to specify a different name
            // when pushing an app, which is used as the cf app name. If
            // they are different, and the
            // corresponding workspace project is accessible, show both.
            // Otherwise, show the cf app name.

            if (element instanceof IModule) {

                IModule module = (IModule) element;

                // Find the corresponding Cloud Foundry-aware application
                // Module.
                DockerFoundryApplicationModule appModule = cloudServer
                        .getExistingCloudModule((IModule) element);

                if (appModule != null) {
                    String cfAppName = appModule.getDeployedApplicationName();

                    if (cfAppName != null) {

                        // Be sure not to show a null WTP module name,
                        // although
                        // that should not be encountered
                        if (moduleName != null && !cfAppName.equals(moduleName)
                                && DockerFoundryProperties.isModuleProjectAccessible
                                        .testProperty(new IModule[] { module }, cloudServer)) {
                            moduleName = cfAppName + " (" + moduleName + ")"; //$NON-NLS-1$ //$NON-NLS-2$
                        } else {
                            moduleName = cfAppName;
                        }
                    }
                }
            }

            return moduleName;
        }

    });
    applicationsViewer.setInput(new CloudApplication[0]);
    applicationsViewer.setSorter(new DockerFoundryViewerSorter());

    applicationsViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            IModule module = (IModule) selection.getFirstElement();

            if (currentModule != module) {
                currentModule = module;
                getManagedForm().fireSelectionChanged(ApplicationMasterPart.this, selection);
            }
        }
    });
    GridDataFactory.fillDefaults().grab(true, true).hint(250, SWT.DEFAULT)
            .applyTo(applicationsViewer.getControl());

    int ops = DND.DROP_COPY | DND.DROP_LINK | DND.DROP_DEFAULT;
    Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
    ApplicationViewersDropAdapter listener = new ApplicationViewersDropAdapter(applicationsViewer);
    applicationsViewer.addDropSupport(ops, transfers, listener);

    // create context menu
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            fillApplicationsContextMenu(manager);
        }
    });

    Menu menu = menuManager.createContextMenu(applicationsViewer.getControl());
    applicationsViewer.getControl().setMenu(menu);
    editorPage.getSite().registerContextMenu(menuManager, applicationsViewer);

    Action addRemoveApplicationAction = new Action(Messages.ApplicationMasterPart_TEXT_ADD_REMOVE,
            ImageResource.getImageDescriptor(ImageResource.IMG_ETOOL_MODIFY_MODULES)) {
        @Override
        public void run() {
            ModifyModulesWizard wizard = new ModifyModulesWizard(cloudServer.getServerOriginal());
            WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
            dialog.open();
        }
    };
    toolBarManager.add(addRemoveApplicationAction);

    // Fix for STS-2996. Moved from CloudFoundryApplicationsEditorPage
    toolBarManager.add(RefreshEditorAction.getRefreshAction(editorPage, null));
    toolBarManager.update(true);
    section.setTextClient(headerComposite);

    getManagedForm().getToolkit().paintBordersFor(client);
}

From source file:cn.dockerfoundry.ide.eclipse.server.ui.internal.editor.ApplicationMasterPart.java

License:Open Source License

private void createServicesSection() {
    servicesSection = toolkit.createSection(getSection().getParent(),
            Section.TITLE_BAR | Section.DESCRIPTION | Section.TWISTIE);
    servicesSection.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(servicesSection);
    servicesSection.setText(Messages.COMMONTXT_SERVICES);
    servicesSection.setExpanded(true);//  w ww  .j  a v a  2  s  . co m
    servicesSection.setDescription(Messages.ApplicationMasterPart_TEXT_SERVICES_DESCRIP);
    // NOTE:Comment out as keeping section collapsed by default causes zero
    // height tables if no services are provided
    // servicesSection.addExpansionListener(new ExpansionAdapter() {
    //
    // @Override
    // public void expansionStateChanged(ExpansionEvent e) {
    // userExpanded = true;
    // }
    // });

    Composite client = toolkit.createComposite(servicesSection);
    client.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(client);
    servicesSection.setClient(client);

    Composite headerComposite = toolkit.createComposite(servicesSection, SWT.NONE);
    RowLayout rowLayout = new RowLayout();
    rowLayout.marginTop = 0;
    rowLayout.marginBottom = 0;
    headerComposite.setLayout(rowLayout);
    headerComposite.setBackground(null);

    ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
    toolBarManager.createControl(headerComposite);

    servicesViewer = new TableViewer(toolkit.createTable(client, SWT.MULTI));
    new ServiceViewerConfigurator().configureViewer(servicesViewer);

    servicesViewer.setContentProvider(new TreeContentProvider());
    servicesViewer.setLabelProvider(new ServicesTreeLabelProvider(servicesViewer) {

        protected Image getColumnImage(CloudService service, ServiceViewColumn column) {
            return null;
        }

    });
    servicesViewer.setSorter(new ServiceViewerSorter(servicesViewer) {

        @Override
        protected int compare(DockerApplicationService service1, DockerApplicationService service2,
                ServiceViewColumn sortColumn) {

            return super.compare(service1, service2, sortColumn);
        }

    });
    DockerApplicationService[] servicesArray = new DockerApplicationService[this.services.size()];
    this.services.toArray(servicesArray);
    servicesViewer.setInput(servicesArray);
    //      servicesViewer.setInput(this.services);

    GridDataFactory.fillDefaults().grab(true, true).applyTo(servicesViewer.getControl());

    //      Action addServiceAction = new Action(Messages.COMMONTXT_ADD_SERVICE, CloudFoundryImages.NEW_SERVICE) {
    //         @Override
    //         public void run() {
    //            CloudFoundryServiceWizard wizard = new CloudFoundryServiceWizard(cloudServer);
    //            WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
    //            wizard.setParent(dialog);
    //            dialog.setPageSize(900, 600);
    //            dialog.setBlockOnOpen(true);
    //            dialog.open();
    //         }
    //      };
    //      toolBarManager.add(addServiceAction);
    //      toolBarManager.update(true);
    servicesSection.setTextClient(headerComposite);

    // create context menu
    //      MenuManager menuManager = new MenuManager();
    //      menuManager.setRemoveAllWhenShown(true);
    //      menuManager.addMenuListener(new IMenuListener() {
    //
    //         public void menuAboutToShow(IMenuManager manager) {
    //            fillServicesContextMenu(manager);
    //         }
    //      });

    //      Menu menu = menuManager.createContextMenu(servicesViewer.getControl());
    //      servicesViewer.getControl().setMenu(menu);
    //      editorPage.getSite().registerContextMenu(menuManager, servicesViewer);

    // Create drag source on the table
    int ops = DND.DROP_COPY;
    Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
    DragSourceAdapter listener = new DragSourceAdapter() {
        @Override
        public void dragSetData(DragSourceEvent event) {
            IStructuredSelection selection = (IStructuredSelection) servicesViewer.getSelection();
            event.data = selection.getFirstElement();
            LocalSelectionTransfer.getTransfer().setSelection(selection);
        }

        @Override
        public void dragStart(DragSourceEvent event) {
            if (event.detail == DND.DROP_NONE || event.detail == DND.DROP_DEFAULT) {
                event.detail = DND.DROP_COPY;
            }
            dragSetData(event);
        }

    };
    servicesViewer.addDragSupport(ops, transfers, listener);

    getManagedForm().getToolkit().paintBordersFor(client);

}

From source file:cn.dockerfoundry.ide.eclipse.server.ui.internal.wizards.DockerFoundryApplicationServicesWizardPage.java

License:Open Source License

public void createControl(Composite parent) {

    setDescription(DESCRIPTION);//from  w ww .j  a v a 2 s. co  m
    ImageDescriptor banner = DockerFoundryImages.getWizardBanner(serverTypeId);
    if (banner != null) {
        setImageDescriptor(banner);
    }

    Composite tableArea = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(1).applyTo(tableArea);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(tableArea);

    Composite toolBarArea = new Composite(tableArea, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(toolBarArea);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(toolBarArea);

    Label label = new Label(toolBarArea, SWT.NONE);
    GridDataFactory.fillDefaults().grab(false, false).align(SWT.BEGINNING, SWT.CENTER).applyTo(label);
    label.setText(Messages.DockerFoundryApplicationServicesWizardPage_LABEL_SELECT_SERVICE);

    Table table = new Table(tableArea, SWT.BORDER | SWT.SINGLE | SWT.CHECK);

    GridDataFactory.fillDefaults().grab(true, true).applyTo(table);

    ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
    ToolBar bar = toolBarManager.createControl(toolBarArea);
    GridDataFactory.fillDefaults().align(SWT.END, SWT.BEGINNING).grab(true, false).applyTo(bar);

    servicesViewer = new CheckboxTableViewer(table);

    servicesViewer.setContentProvider(new TreeContentProvider());
    servicesViewer.setLabelProvider(new ServicesTreeLabelProvider(servicesViewer) {

        protected Image getColumnImage(DockerApplicationService service, ServiceViewColumn column) {

            return null;
        }

    });
    servicesViewer.setSorter(new ServiceViewerSorter(servicesViewer) {

        @Override
        protected int compare(DockerApplicationService service1, DockerApplicationService service2,
                ServiceViewColumn sortColumn) {

            return super.compare(service1, service2, sortColumn);
        }

    });

    new ServiceViewerConfigurator().enableAutomaticViewerResizing().configureViewer(servicesViewer);

    servicesViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            Object[] services = servicesViewer.getCheckedElements();
            if (services != null) {
                selectedServicesToBind.clear();
                for (Object obj : services) {
                    DockerApplicationService service = (DockerApplicationService) obj;
                    selectedServicesToBind.add(service.getName());
                }
                setServicesToBindInDescriptor();
            }
        }
    });

    Action addServiceAction = new Action(Messages.COMMONTXT_ADD_SERVICE, DockerFoundryImages.NEW_SERVICE) {

        public void run() {
            // Do not create the service right away.
            boolean deferAdditionOfService = true;

            DockerFoundryServiceWizard wizard = new DockerFoundryServiceWizard(cloudServer,
                    deferAdditionOfService);
            WizardDialog dialog = new WizardDialog(getShell(), wizard);
            wizard.setParent(dialog);
            dialog.setPageSize(900, 600);
            dialog.setBlockOnOpen(true);

            if (dialog.open() == Window.OK) {
                // This cloud service does not yet exist. It will be created
                // outside of the wizard
                List<List<ServiceInstance>> addedService = wizard.getServices();
                if (addedService != null) {
                    List<DockerApplicationService> _addedServiceList = new ArrayList<DockerApplicationService>();
                    for (List<ServiceInstance> list : addedService) {
                        for (ServiceInstance serviceInstance : list) {
                            DockerApplicationService e = new DockerApplicationService();
                            e.setName(serviceInstance.getName());
                            e.setLinkName(serviceInstance.getUserDefinedName());
                            _addedServiceList.add(e);
                        }
                    }
                    addServices(_addedServiceList);
                }
            }
        }

        public String getToolTipText() {
            return Messages.DockerFoundryApplicationServicesWizardPage_TEXT_TOOLTIP;
        }
    };
    toolBarManager.add(addServiceAction);

    toolBarManager.update(true);

    setControl(tableArea);
    setInput();
}

From source file:com.agynamix.platform.frontend.gui.CustomToolbar.java

License:Open Source License

public Composite createContents(Composite parent) {
    final Composite toolbar = new Composite(parent, SWT.NONE);
    GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL);
    toolbar.setLayoutData(data);// w w w  . ja v a2  s .c o m
    //    toolbar.addListener(SWT.Resize, new Listener() {
    //      public void handleEvent(Event event)
    //      {
    //        GradientHelper.applyGradientBG(toolbar);
    //      }
    //    });

    GridLayout tbLayout = new GridLayout();
    tbLayout.numColumns = 2;
    tbLayout.marginTop = 0;
    tbLayout.marginBottom = 0;
    tbLayout.marginLeft = 0;
    tbLayout.marginRight = 0;
    toolbar.setLayout(tbLayout);

    ToolBarManager tbm = new ToolBarManager(SWT.FLAT);
    for (IContributionItem item : toolbarItems) {
        tbm.add(item);
    }
    tbm.createControl(toolbar);

    addSearchBar(toolbar);

    return toolbar;
}