Example usage for org.eclipse.jface.viewers StructuredSelection getFirstElement

List of usage examples for org.eclipse.jface.viewers StructuredSelection getFirstElement

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers StructuredSelection getFirstElement.

Prototype

@Override
    public Object getFirstElement() 

Source Link

Usage

From source file:es.cv.gvcase.mdt.db.properties.sections.DiagramNamePropertySection.java

License:Open Source License

/**
 * Store the selected <Diagram>//from   w ww. j  av  a2s  .c o m
 */
@Override
public void setInput(IWorkbenchPart part, ISelection selection) {
    super.setInput(part, selection);
    if (selection instanceof StructuredSelection) {
        StructuredSelection ss = (StructuredSelection) selection;
        Object selected = ss.getFirstElement();
        if (selected instanceof EditPart) {
            Object model = ((EditPart) selected).getModel();
            if (model instanceof Diagram) {
                diagram = (Diagram) model;
            }
        } else if (selected instanceof Diagram) {
            diagram = (Diagram) selected;
        } else {
            diagram = null;
        }
    }
}

From source file:eu.aniketos.wp1.ststool.commitments.view.part.CommitmentsView.java

License:Open Source License

/**
 * This is a callback that will allow us to create the viewer and initialize it.
 *//*from  w w  w  .  j  a  v  a 2s. c o  m*/
@Override
public void createPartControl(Composite parent) {

    SashForm sashForm = new SashForm(parent, SWT.BORDER | SWT.VERTICAL);
    sashForm.setSashWidth(1);

    Composite tableComposite = new Composite(sashForm, SWT.NONE);
    tableComposite.setLayout(new FillLayout());
    table = new CommitmentTable(tableComposite, SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
    table.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            if (event.getSelection() instanceof StructuredSelection) {
                StructuredSelection s = (StructuredSelection) event.getSelection();
                if (s.getFirstElement() instanceof ICommitment) {
                    ICommitment c = (ICommitment) s.getFirstElement();
                    descriptionArea.setText(c.getDescritption());
                }
            }
        }
    });
    {

        Composite composite_1 = new Composite(sashForm, SWT.NONE);
        composite_1.setLayout(new FormLayout());

        Label lblDescription = new Label(composite_1, SWT.NONE);
        FormData fd_lblDescription = new FormData();
        fd_lblDescription.right = new FormAttachment(100, -10);
        fd_lblDescription.top = new FormAttachment(0, 10);
        fd_lblDescription.left = new FormAttachment(0, 10);
        lblDescription.setLayoutData(fd_lblDescription);
        lblDescription.setText("Description:");

        Composite composite_2 = new Composite(composite_1, SWT.NONE);
        FormData fd_composite_2 = new FormData();
        fd_composite_2.bottom = new FormAttachment(100, -10);
        fd_composite_2.right = new FormAttachment(100, -10);
        fd_composite_2.top = new FormAttachment(lblDescription, 6);
        fd_composite_2.left = new FormAttachment(0, 10);
        composite_2.setLayoutData(fd_composite_2);

        composite_2.setLayout(new FormLayout());
        composite_2.addPaintListener(new BorderPainter());

        descriptionArea = new Text(composite_2, SWT.NONE);
        descriptionArea.setBackground(descriptionArea.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
        FormData fd_text = new FormData();
        int x = 3;
        fd_text.bottom = new FormAttachment(100, -x);
        fd_text.right = new FormAttachment(100, -x);
        fd_text.top = new FormAttachment(0, x);
        fd_text.left = new FormAttachment(0, x);
        descriptionArea.setLayoutData(fd_text);
        descriptionArea.setEditable(false);
    }
    sashForm.setWeights(new int[] { 1, 1 });

    createViewPulldownMenu();
    CommitmentManager cm = CommitmentManager.getManager();
    cm.addCommitmentListener(this);
}

From source file:eu.aniketos.wp1.ststool.diagram.custom.utility.SelectObjectsDialog.java

License:Open Source License

/**
 * Create contents of the dialog.//  w  w  w  . ja v  a2s. co m
 * 
 * @param parent
 */
@Override
protected Control createDialogArea(Composite parent) {

    Composite container = (Composite) super.createDialogArea(parent);
    container.setLayout(new FormLayout());

    Label lblObjectsName = new Label(container, SWT.CENTER);
    FormData fd_lblObjectsName = new FormData();
    fd_lblObjectsName.top = new FormAttachment(0, 10);
    fd_lblObjectsName.right = new FormAttachment(50, -50);
    fd_lblObjectsName.left = new FormAttachment(0, 10);
    lblObjectsName.setLayoutData(fd_lblObjectsName);
    lblObjectsName.setText(elementsListLabel + " List");

    Label lblSelObjectsName = new Label(container, SWT.CENTER);
    FormData fd_lblSelObjectsName = new FormData();
    fd_lblSelObjectsName.top = new FormAttachment(0, 10);
    fd_lblSelObjectsName.left = new FormAttachment(50, 50);
    fd_lblSelObjectsName.right = new FormAttachment(100, -10);
    lblSelObjectsName.setLayoutData(fd_lblSelObjectsName);
    lblSelObjectsName.setText(selectedElementsListLabel);

    objectsList = new ColoredListViewer<T>(container);
    FormData fd_actorsList = new FormData();
    fd_actorsList.top = new FormAttachment(lblObjectsName, 10);
    fd_actorsList.bottom = new FormAttachment(100, -10);
    fd_actorsList.right = new FormAttachment(50, -50);
    fd_actorsList.left = new FormAttachment(0, 10);
    objectsList.getComposite().setLayoutData(fd_actorsList);

    objectsList.setLabelProvider(labelProvider);
    if (sorter != null)
        objectsList.setSorter(sorter);
    objectsList.setInput(objects);
    objectsList.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            if (event.getSelection() instanceof StructuredSelection) {
                StructuredSelection ss = (StructuredSelection) event.getSelection();
                add((T) ss.getFirstElement());
            }
        }
    });

    selectedObjectsList = new ColoredListViewer<T>(container);
    FormData fd_selectedActorList = new FormData();
    fd_selectedActorList.top = new FormAttachment(lblSelObjectsName, 10);
    fd_selectedActorList.left = new FormAttachment(50, 50);
    fd_selectedActorList.right = new FormAttachment(100, -10);
    fd_selectedActorList.bottom = new FormAttachment(100, -10);
    selectedObjectsList.getComposite().setLayoutData(fd_selectedActorList);

    selectedObjectsList.setLabelProvider(labelProvider);
    if (sorter != null)
        selectedObjectsList.setSorter(sorter);
    selectedObjectsList.setInput(selectedObjects);
    selectedObjectsList.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {

            if (event.getSelection() instanceof StructuredSelection) {
                StructuredSelection ss = (StructuredSelection) event.getSelection();
                remove((T) ss.getFirstElement());
            }
        }
    });

    /*selectedObjectsList = new ListViewer(container, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
    org.eclipse.swt.widgets.List selectedActorsListlist = selectedObjectsList.getList();
    FormData fd_selectedActorList = new FormData();
    fd_selectedActorList.top = new FormAttachment(lblSelObjectsName, 10);
    fd_selectedActorList.left = new FormAttachment(50, 50);
    fd_selectedActorList.right = new FormAttachment(100, -10);
    fd_selectedActorList.bottom = new FormAttachment(100, -10);
    selectedActorsListlist.setLayoutData(fd_selectedActorList);
            
    selectedObjectsList.setContentProvider(new ArrayContentProvider());
    selectedObjectsList.setLabelProvider(labelProvider);
    selectedObjectsList.setInput(selectedObjects);
    selectedObjectsList.addDoubleClickListener(new IDoubleClickListener() {
            
       @Override
       public void doubleClick(DoubleClickEvent event) {
            
    if (event.getSelection() instanceof StructuredSelection) {
       StructuredSelection ss = (StructuredSelection) event.getSelection();
       remove((T) ss.getFirstElement());
    }
       }
    });*/

    Button butAddAll = new Button(container, SWT.NONE);
    FormData fd_butAddAll = new FormData();
    fd_butAddAll.left = new FormAttachment(50, -40);
    fd_butAddAll.width = 80;
    fd_butAddAll.top = new FormAttachment(50, 10);
    butAddAll.setLayoutData(fd_butAddAll);
    butAddAll.setText("Add All");
    butAddAll.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {

            add((List<T>) objectsList.getInput());
        }
    });

    Button butRemAll = new Button(container, SWT.NONE);
    FormData fd_butRemAll = new FormData();
    fd_butRemAll.left = new FormAttachment(50, -40);
    fd_butRemAll.width = 80;
    fd_butRemAll.top = new FormAttachment(butAddAll, 10);
    butRemAll.setLayoutData(fd_butRemAll);
    butRemAll.setText("Remove all");
    butRemAll.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {

            remove((List<T>) selectedObjectsList.getInput());
        }
    });

    Button butRem = new Button(container, SWT.NONE);
    FormData fd_butRem = new FormData();
    fd_butRem.width = 80;
    fd_butRem.left = new FormAttachment(50, -40);
    fd_butRem.bottom = new FormAttachment(butAddAll, -10);
    fd_butRem.width = 80;
    butRem.setLayoutData(fd_butRem);
    butRem.setText("<");
    butRem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {

            if (selectedObjectsList.getSelection() instanceof StructuredSelection) {
                StructuredSelection ss = (StructuredSelection) selectedObjectsList.getSelection();
                remove((List<T>) ss.toList());
            }
        }
    });

    Button butAdd = new Button(container, SWT.NONE);
    butAdd.setText(">");
    FormData fd_butAdd = new FormData();
    fd_butAdd.bottom = new FormAttachment(butRem, -10);
    fd_butAdd.width = 80;
    fd_butAdd.left = new FormAttachment(50, -40);
    butAdd.setLayoutData(fd_butAdd);

    butAdd.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {

            if (objectsList.getSelection() instanceof StructuredSelection) {
                StructuredSelection ss = (StructuredSelection) objectsList.getSelection();
                add((List<T>) ss.toList());
            }
        }
    });

    return container;
}

From source file:eu.esdihumboldt.hale.io.haleconnect.ui.projects.ChooseHaleConnectProjectWizardPage.java

License:Open Source License

/**
 * @see eu.esdihumboldt.hale.ui.util.wizard.ConfigurationWizardPage#updateConfiguration(java.lang.Object)
 *///from   w  ww  .ja  v a2 s  . c o  m
@Override
public boolean updateConfiguration(HaleConnectProjectConfig configuration) {
    if (projects.getSelection().isEmpty()) {
        return false;
    }

    StructuredSelection selection = (StructuredSelection) projects.getSelection();
    if (!(selection.getFirstElement() instanceof HaleConnectProjectInfo)) {
        return false;
    }

    HaleConnectProjectInfo pi = (HaleConnectProjectInfo) selection.getFirstElement();
    configuration.setProjectId(pi.getId());
    configuration.setProjectName(pi.getName());
    configuration.setOwner(pi.getOwner());
    configuration.setLastModified(pi.getLastModified());

    return true;
}

From source file:eu.esdihumboldt.hale.io.haleconnect.ui.projects.ChooseHaleConnectProjectWizardPage.java

License:Open Source License

/**
 * @see eu.esdihumboldt.hale.ui.util.wizard.ConfigurationWizardPage#createContent(org.eclipse.swt.widgets.Composite)
 *//*ww  w  . j  av a2s . co m*/
@Override
protected void createContent(Composite parent) {
    Composite page = new Composite(parent, SWT.NONE);
    page.setLayout(new GridLayout(4, false));

    keywordFilter = new Text(page, SWT.SEARCH | SWT.ICON_SEARCH | SWT.BORDER | SWT.ICON_CANCEL);
    keywordFilter.setMessage("Enter search text here...");
    GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(keywordFilter);

    ownerFilter = new ComboViewer(page);
    GridDataFactory.fillDefaults().grab(false, false).applyTo(ownerFilter.getControl());
    ownerFilter.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            new Object();
        }

        @Override
        public void dispose() {
            //
        }

        @Override
        public Object[] getElements(Object inputElement) {
            if (inputElement instanceof List<?>) {
                List<?> elements = (List<?>) inputElement;
                return elements.toArray();
            } else if (inputElement instanceof Object[]) {
                return (Object[]) inputElement;
            }

            return new Object[] {};
        }
    });
    ownerFilter.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof OwnerFilterEntry) {
                return ((OwnerFilterEntry) element).getLabel();
            }

            return super.getText(element);
        }

    });

    List<OwnerFilterEntry> availableFilters = new ArrayList<>();
    availableFilters.add(NULL_FILTER);
    availableFilters.add(new OwnerFilterEntry(
            new Owner[] { new Owner(OwnerType.USER, haleConnect.getSession().getUserId()) }, "My projects"));

    List<Owner> orgs = new ArrayList<>();
    for (String orgId : haleConnect.getSession().getOrganisationIds()) {
        orgs.add(new Owner(OwnerType.ORGANISATION, orgId));
    }
    if (!orgs.isEmpty()) {
        availableFilters.add(new OwnerFilterEntry(orgs.toArray(new Owner[] {}), "My organisation's projects"));
    }

    ownerFilter.setInput(availableFilters);
    ownerFilter.setSelection(new StructuredSelection(NULL_FILTER));

    Composite tableComposite = new Composite(page, SWT.NONE);
    TableColumnLayout columnLayout = new TableColumnLayout();
    tableComposite.setLayout(columnLayout);

    projects = new TableViewer(tableComposite,
            SWT.V_SCROLL | SWT.BORDER | SWT.H_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION);
    projects.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            update();
        }
    });

    TableViewerColumn nameColumn = new TableViewerColumn(projects, SWT.LEAD);
    nameColumn.getColumn().setText("Project name");
    nameColumn.setLabelProvider(new ColumnLabelProvider() {

        /**
         * @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
         */
        @Override
        public String getText(Object element) {
            if (element instanceof HaleConnectProjectInfo) {
                return ((HaleConnectProjectInfo) element).getName();
            }

            return element.toString();
        }

    });
    columnLayout.setColumnData(nameColumn.getColumn(), new ColumnWeightData(45, 200, true));

    TableViewerColumn authorColumn = new TableViewerColumn(projects, SWT.LEAD);
    authorColumn.getColumn().setText("Author");
    authorColumn.setLabelProvider(new ColumnLabelProvider() {

        /**
         * @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
         */
        @Override
        public String getText(Object element) {
            if (element instanceof HaleConnectProjectInfo) {
                return ((HaleConnectProjectInfo) element).getAuthor();
            }

            return element.toString();
        }

    });
    columnLayout.setColumnData(authorColumn.getColumn(), new ColumnWeightData(20, 50, true));

    TableViewerColumn ownerColumn = new TableViewerColumn(projects, SWT.LEAD);
    ownerColumn.getColumn().setText("Owner");
    ownerColumn.setLabelProvider(new ColumnLabelProvider() {

        /**
         * @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
         */
        @Override
        public String getText(Object element) {
            if (element instanceof HaleConnectProjectInfo) {
                Owner owner = ((HaleConnectProjectInfo) element).getOwner();
                if (owner.isUser()) {
                    try {
                        HaleConnectUserInfo user = haleConnect.getUserInfo(owner.getId());
                        if (!StringUtils.isEmpty(user.getFullName())) {
                            return user.getFullName();
                        } else if (!StringUtils.isEmpty(user.getScreenName())) {
                            return user.getScreenName();
                        } else {
                            return MessageFormat.format("<user {0}>", user.getUserId());
                        }
                    } catch (HaleConnectException e) {
                        log.error(e.getMessage(), e);
                        return MessageFormat.format("<user {0}>", owner.getId());
                    }
                } else if (owner.isOrganisation()) {
                    try {
                        return haleConnect.getOrganisationInfo(owner.getId()).getName();
                    } catch (HaleConnectException e) {
                        log.error(e.getMessage(), e);
                        return MessageFormat.format("<organisation {0}>", owner.getId());
                    }
                } else {
                    return "<unknown owner type> ID: " + owner.getId();
                }
            }

            return element.toString();
        }

    });
    columnLayout.setColumnData(ownerColumn.getColumn(), new ColumnWeightData(35, 100, true));

    final Table projectsTable = projects.getTable();
    projectsTable.setHeaderVisible(true);
    projectsTable.setLinesVisible(true);

    tableComposite.setLayoutData(GridDataFactory.fillDefaults().span(4, 1).grab(true, true).create());
    projects.setContentProvider(ArrayContentProvider.getInstance());

    populateProjects(projectsTable);

    final ProjectFilter projectFilter = new ProjectFilter(projects);
    projects.addFilter(projectFilter);

    ownerFilter.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            if (event.getSelection() instanceof StructuredSelection) {
                StructuredSelection selection = (StructuredSelection) event.getSelection();
                if (selection.getFirstElement() instanceof OwnerFilterEntry) {
                    OwnerFilterEntry selectedFilter = (OwnerFilterEntry) selection.getFirstElement();
                    if (selectedFilter.equals(NULL_FILTER)) {
                        projectFilter.clearOwnerFilter();
                    } else {
                        projectFilter.filterByOwners(Arrays.asList(selectedFilter.getOwner()));
                    }
                }
            }
        }
    });

    keywordFilter.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            projectFilter.setSearchText(keywordFilter.getText());
        }
    });

    final Button refresh = new Button(page, SWT.FLAT);
    refresh.setText("Refresh");
    GridDataFactory.fillDefaults().span(1, 1).grab(false, false).applyTo(refresh);
    refresh.addSelectionListener(new SelectionAdapter() {

        /**
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            populateProjects(projectsTable);
        }

    });

    ownerFilter.getControl().setFocus();
    setControl(page);

    update();

}

From source file:eu.esdihumboldt.hale.io.haleconnect.ui.projects.ChooseHaleConnectProjectWizardPage.java

License:Open Source License

private void update() {
    StructuredSelection selection = (StructuredSelection) projects.getSelection();
    if (selection.getFirstElement() instanceof HaleConnectProjectInfo) {
        setPageComplete(true);/*from   www.j  a v a2s  .  c o  m*/
    } else {
        setPageComplete(false);
    }
}

From source file:eu.geclipse.jsdl.ui.internal.pages.sections.SweepOrderSection.java

License:Open Source License

private void createSection(final Composite parent, final FormToolkit toolkit) {
    // general form settings
    this.shell = parent.getShell();
    String sectionTitle = "Sweep order"; //$NON-NLS-1$
    String sectionDescription = "Specify the order of parameters sweep and their dependency from each other"; //$NON-NLS-1$
    Composite client = FormSectionFactory.createGridStaticSection(toolkit, parent, sectionTitle,
            sectionDescription, 3);//from   ww w.  j av a  2 s . c  o  m
    // sweep order tree
    Composite treeComp = toolkit.createComposite(client);
    GridData gData = new GridData(GridData.FILL_BOTH);
    gData.horizontalSpan = 3;
    treeComp.setLayoutData(gData);
    treeComp.setLayout(new GridLayout(2, false));
    this.viewer = new TreeViewer(treeComp, SWT.BORDER);
    this.viewer.setContentProvider(new SweepOrderCProvider());
    this.viewer.setLabelProvider(new SweepOrderLProvider());
    gData = new GridData(GridData.GRAB_HORIZONTAL);
    gData = new GridData();
    gData.horizontalAlignment = GridData.FILL;
    gData.verticalAlignment = GridData.FILL;
    gData.grabExcessHorizontalSpace = true;
    gData.verticalSpan = 6;
    gData.heightHint = 300;
    this.viewer.getTree().setLayoutData(gData);
    this.viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(final SelectionChangedEvent event) {
            ISelection sel = SweepOrderSection.this.viewer.getSelection();
            if (sel instanceof StructuredSelection) {
                StructuredSelection sSel = (StructuredSelection) sel;
                if (sSel.getFirstElement() instanceof SweepType) {
                    SweepType type = (SweepType) sSel.getFirstElement();
                    int i = 0;
                    boolean found = false;
                    for (String item : SweepOrderSection.this.sweepCombo.getItems()) {
                        if (item.equals(getNameForSweep(type))) {
                            found = true;
                            break;
                        }
                        i++;
                    }
                    if (found) {
                        SweepOrderSection.this.sweepCombo.select(i);
                        setValuesField(SweepOrderSection.this.adapter.getValuesForParameter(
                                SweepOrderSection.this.sweepCombo.getItem(i),
                                SweepOrderSection.this.inerSweepList));
                    }
                } else if (sSel.isEmpty()) {
                    SweepOrderSection.this.sweepCombo.deselectAll();
                    setValuesField(null);
                }
            }
            updateButtons();
        }
    });
    this.manager = createMenu();
    // tree buttons composite
    Composite buttonComp = toolkit.createComposite(treeComp);
    buttonComp.setLayout(new GridLayout(1, true));
    this.newButton = toolkit.createButton(buttonComp, "New sweep...", SWT.PUSH); //$NON-NLS-1$
    this.newButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    this.independentButton = toolkit.createButton(buttonComp, "Independent sweep...", //$NON-NLS-1$
            SWT.PUSH);
    gData = new GridData(GridData.FILL_HORIZONTAL);
    gData.verticalIndent = 15;
    this.independentButton.setLayoutData(gData);
    this.sameLevelButton = toolkit.createButton(buttonComp, "Sweep on the same level...", //$NON-NLS-1$
            SWT.PUSH);
    this.sameLevelButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    this.innerButton = toolkit.createButton(buttonComp, "Inner sweep...", //$NON-NLS-1$
            SWT.PUSH);
    this.innerButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    this.deleteButton = toolkit.createButton(buttonComp, "Delete", SWT.PUSH); //$NON-NLS-1$
    gData = new GridData(GridData.FILL_HORIZONTAL);
    gData.verticalIndent = 15;
    this.deleteButton.setLayoutData(gData);
    updateButtons();
    // values controls
    toolkit.createLabel(client, "Sweep element"); //$NON-NLS-1$
    this.sweepCombo = new Combo(client, SWT.NONE | SWT.READ_ONLY);
    gData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL);
    gData.widthHint = 200;
    gData.horizontalSpan = 2;
    this.sweepCombo.setLayoutData(gData);
    this.sweepCombo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            setValuesField(SweepOrderSection.this.adapter.getValuesForParameter(
                    SweepOrderSection.this.sweepCombo.getText(), SweepOrderSection.this.inerSweepList));
            updateButtons();
        }
    });
    toolkit.createLabel(client, "Parameter values\n(put each value in new line)"); //$NON-NLS-1$
    this.textArea = new Text(client, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.BORDER);
    gData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
    gData.heightHint = 70;
    gData.widthHint = 160;
    this.textArea.setLayoutData(gData);
    this.textArea.addKeyListener(new KeyListener() {

        public void keyPressed(final KeyEvent e) {
            // do nothing
        }

        public void keyReleased(final KeyEvent e) {
            List<String> val = new ArrayList<String>();
            for (String value : SweepOrderSection.this.textArea.getText()
                    .split(System.getProperty("line.separator"))) //$NON-NLS-1$
            {
                val.add(value);
            }
            SweepType sweep = SweepOrderSection.this.adapter.findSweepElement(
                    SweepOrderSection.this.sweepCombo.getText(), SweepOrderSection.this.inerSweepList);
            AssignmentType assignment = null;
            if (sweep != null && sweep.getAssignment() != null) {
                for (int j = 0; j < sweep.getAssignment().size(); j++) {
                    if (((AssignmentType) sweep.getAssignment().get(j)).getParameter()
                            .contains(SweepOrderSection.this.sweepCombo.getText())) {
                        assignment = (AssignmentType) sweep.getAssignment().get(j);
                        break;
                    }
                }
            }
            if (assignment != null) {
                SweepOrderSection.this.adapter.setFunctionValues(assignment, val);
                contentChanged();
            }
            updateButtons();
        }
    });
    // values buttons composite
    Composite buttonValComp = toolkit.createComposite(client);
    buttonValComp.setLayout(new GridLayout(1, true));
    this.addFunctionButton = toolkit.createButton(buttonValComp, "Define loop...", //$NON-NLS-1$
            SWT.PUSH);
    gData = new GridData();
    this.addFunctionButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            SweepLoopDialog dialog = new SweepLoopDialog(SweepOrderSection.this.shell);
            if (dialog.open() == Window.OK) {
                List<BigInteger> exceptions = new ArrayList<BigInteger>();
                if (dialog.getExceptionsReturn() != null) {
                    for (String exc : dialog.getExceptionsReturn()) {
                        exceptions.add(new BigInteger(exc));
                    }
                }
                appendTextToTextArea(SweepOrderSection.this.adapter.createLOOPString(
                        new BigInteger(dialog.getStartReturn()), new BigInteger(dialog.getEndReturn()),
                        new BigInteger(dialog.getStepReturn()), exceptions));
                updateButtons();
            }
        }
    });
    this.addFunctionButton.setLayoutData(gData);
    updateButtons();
    addButtonsListeners();
}

From source file:eu.geclipse.jsdl.ui.internal.pages.sections.SweepOrderSection.java

License:Open Source License

protected void addChangesForEachChange() {
    ISelection sel = this.viewer.getSelection();
    if (sel instanceof StructuredSelection) {
        StructuredSelection sSel = (StructuredSelection) sel;
        if (sSel.getFirstElement() instanceof SweepType) {
            SweepType type = (SweepType) sSel.getFirstElement();
            List<String> adapterList = this.adapter.getElementsList();
            adapterList.removeAll(getInerSweepNames());
            ParametersDialog dialog = new ParametersDialog(this.shell, adapterList, getInerSweepNames(),
                    getNameForSweep(type), ParametersDialog.WITH_REF);
            // dialog.setTitle( "Add inner sweep" );
            if (dialog.open() == Window.OK) {
                performAddChangesForEachChange(dialog.getElementReturn(), dialog.getRefElementReturn(),
                        dialog.getValuesReturn());
            }//from   ww w .j  a  va 2s.com
        }
    }
}

From source file:eu.geclipse.jsdl.ui.internal.pages.sections.SweepOrderSection.java

License:Open Source License

protected void addChangesWith() {
    ISelection sel = this.viewer.getSelection();
    if (sel instanceof StructuredSelection) {
        StructuredSelection sSel = (StructuredSelection) sel;
        if (sSel.getFirstElement() instanceof SweepType) {
            SweepType type = (SweepType) sSel.getFirstElement();
            List<String> adapterList = this.adapter.getElementsList();
            adapterList.removeAll(getInerSweepNames());
            ParametersDialog dialog = new ParametersDialog(this.shell, adapterList, getInerSweepNames(),
                    getNameForSweep(type), ParametersDialog.WITH_REF);
            // dialog.setTitle( "Add sweep on the same level" );
            if (dialog.open() == Dialog.OK) {
                performAddChangesWith(dialog.getElementReturn(), dialog.getRefElementReturn(),
                        dialog.getValuesReturn());
            }//ww w  .j  ava  2s  . c  o  m
        }
    }
}

From source file:eu.geclipse.jsdl.ui.internal.pages.sections.SweepOrderSection.java

License:Open Source License

protected void addIndependent() {
    ISelection sel = this.viewer.getSelection();
    if (sel instanceof StructuredSelection) {
        StructuredSelection sSel = (StructuredSelection) sel;
        if (sSel.getFirstElement() instanceof SweepType) {
            SweepType type = (SweepType) sSel.getFirstElement();
            List<String> adapterList = this.adapter.getElementsList();
            adapterList.removeAll(getInerSweepNames());
            ParametersDialog dialog = new ParametersDialog(this.shell, adapterList, getInerSweepNames(),
                    getNameForSweep(type), ParametersDialog.WITH_REF);
            // dialog.setTitle( "Add independent sweep" );
            if (dialog.open() == Window.OK) {
                performAddIndependent(dialog.getElementReturn(), dialog.getRefElementReturn(),
                        dialog.getValuesReturn());
            }/*from w ww .j  ava2 s.c o  m*/
        }
    }
}