Search in sources :

Example 11 with ControlDecoration

use of org.eclipse.jface.fieldassist.ControlDecoration in project bndtools by bndtools.

the class ReposPreferencePage method createContents.

@Override
protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(1, false);
    layout.marginRight = 10;
    composite.setLayout(layout);
    Group group = new Group(composite, SWT.NONE);
    group.setText("Templates Repositories");
    group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    group.setLayout(new GridLayout(2, false));
    final Button btnEnableTemplateRepo = new Button(group, SWT.CHECK);
    btnEnableTemplateRepo.setText("Enable templates repositories");
    btnEnableTemplateRepo.setSelection(enableTemplateRepo);
    btnEnableTemplateRepo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
    ControlDecoration decoration = new ControlDecoration(btnEnableTemplateRepo, SWT.RIGHT | SWT.TOP, composite);
    decoration.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
    decoration.setMarginWidth(3);
    decoration.setDescriptionText("These repositories are used to load\ntemplates, in addition to repositories\nconfigured in the Bnd OSGi Workspace.");
    decoration.setShowHover(true);
    decoration.setShowOnlyOnFocus(false);
    Label lblRepos = new Label(group, SWT.NONE);
    lblRepos.setText("Repository URLs:");
    lblRepos.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
    final Table tblRepos = new Table(group, SWT.BORDER | SWT.MULTI);
    vwrRepos = new TableViewer(tblRepos);
    vwrRepos.setContentProvider(ArrayContentProvider.getInstance());
    vwrRepos.setLabelProvider(new URLLabelProvider(tblRepos.getDisplay()));
    vwrRepos.setInput(templateRepos);
    GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
    gd.widthHint = 260;
    gd.heightHint = 80;
    tblRepos.setLayoutData(gd);
    tblRepos.setEnabled(enableTemplateRepo);
    final AddRemoveButtonBarPart addRemoveRepoPart = new AddRemoveButtonBarPart();
    Control addRemovePanel = addRemoveRepoPart.createControl(group, SWT.FLAT | SWT.VERTICAL);
    addRemovePanel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    addRemoveRepoPart.setRemoveEnabled(false);
    addRemoveRepoPart.addListener(new AddRemoveListener() {

        @Override
        public void addSelected() {
            doAddRepo();
        }

        @Override
        public void removeSelected() {
            doRemoveRepo();
        }
    });
    vwrRepos.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            addRemoveRepoPart.setRemoveEnabled(!vwrRepos.getSelection().isEmpty());
        }
    });
    tblRepos.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.DEL && e.stateMask == 0)
                doRemoveRepo();
        }
    });
    btnEnableTemplateRepo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent ev) {
            enableTemplateRepo = btnEnableTemplateRepo.getSelection();
            tblRepos.setEnabled(enableTemplateRepo);
            validate();
        }
    });
    return composite;
}
Also used : Group(org.eclipse.swt.widgets.Group) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) AddRemoveButtonBarPart(org.bndtools.utils.swt.AddRemoveButtonBarPart) KeyEvent(org.eclipse.swt.events.KeyEvent) URLLabelProvider(bndtools.shared.URLLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) AddRemoveListener(org.bndtools.utils.swt.AddRemoveButtonBarPart.AddRemoveListener) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 12 with ControlDecoration

use of org.eclipse.jface.fieldassist.ControlDecoration in project bndtools by bndtools.

the class GitCloneURLDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    setTitle(title);
    Composite area = (Composite) super.createDialogArea(parent);
    Composite container = new Composite(area, SWT.NONE);
    container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    container.setLayout(new GridLayout(2, false));
    Label lblRepo = new Label(container, SWT.NONE);
    lblRepo.setText("Clone URL:");
    txtRepository = new Text(container, SWT.BORDER);
    txtRepository.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    if (cloneUri != null)
        txtRepository.setText(cloneUri.toString());
    Label lblName = new Label(container, SWT.NONE);
    lblName.setText("Name:");
    txtName = new Text(container, SWT.BORDER);
    txtName.setMessage("optional");
    txtName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    if (name != null)
        txtName.setText(name);
    new Label(container, SWT.NONE).setText("Branch:");
    txtBranch = new Text(container, SWT.BORDER);
    txtBranch.setMessage("default: " + GitCloneTemplateParams.DEFAULT_BRANCH);
    txtBranch.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    if (branch != null)
        txtBranch.setText(branch);
    ControlDecoration branchDecor = new ControlDecoration(txtBranch, SWT.LEFT, container);
    branchDecor.setDescriptionText("Specify the branch, tag or commit ID you would like to clone from the\nrepository. The default is 'origin/master'.");
    branchDecor.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
    branchDecor.setShowHover(true);
    ModifyListener modifyListener = new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent ev) {
            updateFromInput();
            updateButtons();
        }
    };
    txtRepository.addModifyListener(modifyListener);
    txtName.addModifyListener(modifyListener);
    txtBranch.addModifyListener(modifyListener);
    return area;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) Text(org.eclipse.swt.widgets.Text)

Example 13 with ControlDecoration

use of org.eclipse.jface.fieldassist.ControlDecoration in project bndtools by bndtools.

the class GitHubRepoDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    setTitle(title);
    Composite area = (Composite) super.createDialogArea(parent);
    Composite container = new Composite(area, SWT.NONE);
    container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    container.setLayout(new GridLayout(2, false));
    Label lblRepo = new Label(container, SWT.NONE);
    lblRepo.setText("Repository Name:");
    txtRepository = new Text(container, SWT.BORDER);
    txtRepository.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    txtRepository.setMessage("username/repository");
    if (repository != null)
        txtRepository.setText(repository);
    new Label(container, SWT.NONE).setText("Branch:");
    txtBranch = new Text(container, SWT.BORDER);
    txtBranch.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    txtBranch.setMessage("default branch");
    if (branch != null)
        txtBranch.setText(branch);
    ControlDecoration branchDecor = new ControlDecoration(txtBranch, SWT.LEFT, container);
    branchDecor.setDescriptionText("Specify the branch, tag or commit ID you would like to clone from the\nrepository. We use the default branch specified in GitHub settings.");
    branchDecor.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
    branchDecor.setShowHover(true);
    final Button btnValidate = new Button(container, SWT.PUSH);
    btnValidate.setText("Validate");
    btnValidate.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 2, 1));
    ModifyListener modifyListener = new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent ev) {
            if (!txtRepository.getText().trim().equals(repository)) {
                isValidated = false;
                repository = txtRepository.getText().trim();
            }
            branch = txtBranch.getText().trim();
            updateButtons();
        }
    };
    txtRepository.addModifyListener(modifyListener);
    txtBranch.addModifyListener(modifyListener);
    btnValidate.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            setMessage(null, IMessageProvider.INFORMATION);
            try {
                if (repository == null || repository.isEmpty())
                    throw new GitHubValidationException("No repository name specified");
                if (repository.contains(":/"))
                    throw new GitHubValidationException("Specify GitHub repositories as username/repository");
                IRunnableWithProgress runnable = new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            final GithubRepoDetailsDTO dto = new GitHub(cache, executor).loadRepoDetails(repository).getValue();
                            final URI cloneUri = URI.create(dto.clone_url);
                            btnValidate.getDisplay().asyncExec(new Runnable() {

                                @Override
                                public void run() {
                                    setMessage(String.format("Validated! Clone URL is '%s'. Default branch 'origin/%s'", cloneUri, dto.default_branch), IMessageProvider.INFORMATION);
                                    isValidated = true;
                                    updateButtons();
                                }
                            });
                        } catch (InvocationTargetException e) {
                            throw e;
                        } catch (Exception e) {
                            throw new InvocationTargetException(e);
                        }
                    }
                };
                ProgressRunner.execute(false, runnable, new ProgressMonitorDialog(getParentShell()), btnValidate.getDisplay());
                setErrorMessage(null);
            } catch (InvocationTargetException ex) {
                Throwable t = ex.getCause();
                if (t instanceof FileNotFoundException)
                    setErrorMessage("Could not find the requested repository");
                else
                    setErrorMessage(t.getClass().getSimpleName() + ": " + t.getMessage());
            } catch (GitHubValidationException ex) {
                setErrorMessage(ex.getMessage());
            } catch (Exception ex) {
                setErrorMessage(ex.getClass().getSimpleName() + ": " + ex.getMessage());
            }
        }
    });
    return area;
}
Also used : GitHubValidationException(org.bndtools.templating.jgit.GitHubValidationException) ModifyListener(org.eclipse.swt.events.ModifyListener) GitHub(org.bndtools.templating.jgit.GitHub) Label(org.eclipse.swt.widgets.Label) FileNotFoundException(java.io.FileNotFoundException) URI(java.net.URI) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) Text(org.eclipse.swt.widgets.Text) InvocationTargetException(java.lang.reflect.InvocationTargetException) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) GitHubValidationException(org.bndtools.templating.jgit.GitHubValidationException) GithubRepoDetailsDTO(org.bndtools.templating.jgit.GithubRepoDetailsDTO) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GridData(org.eclipse.swt.layout.GridData)

Example 14 with ControlDecoration

use of org.eclipse.jface.fieldassist.ControlDecoration in project bndtools by bndtools.

the class PluginPropertiesPage method resetPropertyFields.

void resetPropertyFields() {
    // Remove existing controls
    Control[] children = fieldContainer.getChildren();
    for (Control child : children) child.dispose();
    // Add new ones
    if (configElement != null) {
        IConfigurationElement[] propertyElements = configElement.getChildren("property");
        String path = configElement.getAttribute("path");
        String className = configElement.getAttribute("class");
        String summaryMessage = MessageFormat.format("Found {0,choice,0#no properties|1#one property|1<{0} properties} for plug-in class {1}.", propertyElements.length, className);
        if (path != null) {
            properties.put(Constants.PATH_DIRECTIVE, path);
            txtPath.setText(path);
        }
        for (IConfigurationElement propertyElement : propertyElements) {
            final String name = propertyElement.getAttribute("name");
            String value = properties.get(name);
            String propertyType = propertyElement.getAttribute("type");
            String defaultStr = propertyElement.getAttribute("default");
            if (value == null && defaultStr != null) {
                value = defaultStr;
                properties.put(name, defaultStr);
            }
            Label label = new Label(fieldContainer, SWT.NONE);
            label.setText(name);
            if ("boolean".equals(propertyType)) {
                final Button button = new Button(fieldContainer, SWT.CHECK);
                button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));
                button.setSelection("true".equalsIgnoreCase(value));
                button.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        properties.put(name, button.getSelection() ? "true" : "false");
                        changed = true;
                    }
                });
            } else {
                final Text text = new Text(fieldContainer, SWT.BORDER);
                text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
                if (value != null)
                    text.setText(value);
                text.addModifyListener(new ModifyListener() {

                    public void modifyText(ModifyEvent e) {
                        String value = text.getText();
                        if (value == null || value.length() == 0)
                            properties.remove(name);
                        else
                            properties.put(name, value);
                        changed = true;
                    }
                });
            }
            String description = propertyElement.getAttribute("description");
            if (description != null) {
                ControlDecoration decoration = new ControlDecoration(label, SWT.RIGHT | SWT.CENTER);
                decoration.setShowHover(true);
                decoration.setDescriptionText(description);
                decoration.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
            }
            String deprecation = propertyElement.getAttribute("deprecated");
            if (deprecation != null) {
                ControlDecoration decoration = new ControlDecoration(label, SWT.LEFT | SWT.CENTER);
                decoration.setShowHover(true);
                decoration.setDescriptionText("Property deprecated: " + deprecation);
                decoration.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_WARNING).getImage());
            }
        }
        Label summaryLabel = new Label(fieldContainer, SWT.NONE);
        summaryLabel.setText(summaryMessage);
        summaryLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
    }
    mainComposite.layout(true, true);
}
Also used : ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) Control(org.eclipse.swt.widgets.Control) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration)

Example 15 with ControlDecoration

use of org.eclipse.jface.fieldassist.ControlDecoration in project bndtools by bndtools.

the class RunFrameworkPart method createSection.

final void createSection(Section section, FormToolkit tk) {
    section.setText("Core Runtime");
    Composite composite = tk.createComposite(section);
    section.setClient(composite);
    Label lblFramework = new Label(composite, SWT.NONE);
    tk.adapt(lblFramework, true, true);
    lblFramework.setText("OSGi Framework:");
    cmbFramework = new Combo(composite, SWT.DROP_DOWN);
    tk.adapt(cmbFramework);
    tk.paintBordersFor(cmbFramework);
    cmbFramework.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    frameworkViewer = new ComboViewer(cmbFramework);
    frameworkViewer.setUseHashlookup(true);
    frameworkViewer.setContentProvider(fwkContentProvider);
    Label lblExecEnv = tk.createLabel(composite, "Execution Env.:");
    cmbExecEnv = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
    ControlDecoration eeDecor = new ControlDecoration(cmbExecEnv, SWT.LEFT | SWT.TOP, composite);
    eeDecor.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
    eeDecor.setDescriptionText("The runtime Java Virtual Machine will be required/assumed " + "\nto support this Execution Environment");
    eeViewer = new ComboViewer(cmbExecEnv);
    eeViewer.setContentProvider(ArrayContentProvider.getInstance());
    eeViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((EE) element).getEEName();
        }
    });
    eeViewer.setInput(EE.values());
    // Listeners
    cmbFramework.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            lock.ifNotModifying(new Runnable() {

                @Override
                public void run() {
                    markDirty();
                    selectedFramework = cmbFramework.getText();
                }
            });
        }
    });
    frameworkViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            lock.ifNotModifying(new Runnable() {

                @Override
                public void run() {
                    Object element = ((IStructuredSelection) frameworkViewer.getSelection()).getFirstElement();
                    if (element instanceof LoadingContentElement) {
                        return;
                    }
                    markDirty();
                    if (element == null)
                        selectedFramework = null;
                    else
                        selectedFramework = element.toString();
                }
            });
        }
    });
    eeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            lock.ifNotModifying(new Runnable() {

                @Override
                public void run() {
                    markDirty();
                    selectedEE = (EE) ((IStructuredSelection) event.getSelection()).getFirstElement();
                }
            });
        }
    });
    GridLayout layout = new GridLayout(2, false);
    layout.horizontalSpacing = 10;
    composite.setLayout(layout);
    lblFramework.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
    GridData gd;
    gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
    gd.widthHint = 20;
    gd.heightHint = 20;
    cmbFramework.setLayoutData(gd);
    lblExecEnv.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
    gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
    gd.widthHint = 20;
    gd.heightHint = 20;
    cmbExecEnv.setLayoutData(gd);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) LoadingContentElement(bndtools.model.repo.LoadingContentElement) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Aggregations

ControlDecoration (org.eclipse.jface.fieldassist.ControlDecoration)19 Label (org.eclipse.swt.widgets.Label)14 GridData (org.eclipse.swt.layout.GridData)12 Composite (org.eclipse.swt.widgets.Composite)11 GridLayout (org.eclipse.swt.layout.GridLayout)10 Button (org.eclipse.swt.widgets.Button)10 Text (org.eclipse.swt.widgets.Text)10 ModifyEvent (org.eclipse.swt.events.ModifyEvent)9 ModifyListener (org.eclipse.swt.events.ModifyListener)9 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)8 SelectionEvent (org.eclipse.swt.events.SelectionEvent)8 Image (org.eclipse.swt.graphics.Image)6 Combo (org.eclipse.swt.widgets.Combo)6 Control (org.eclipse.swt.widgets.Control)5 FieldDecoration (org.eclipse.jface.fieldassist.FieldDecoration)4 ComboViewer (org.eclipse.jface.viewers.ComboViewer)4 ContentProposalAdapter (org.eclipse.jface.fieldassist.ContentProposalAdapter)3 File (java.io.File)2 IStatus (org.eclipse.core.runtime.IStatus)2 ObservableListContentProvider (org.eclipse.jface.databinding.viewers.ObservableListContentProvider)2