Example usage for org.eclipse.jface.viewers ComboViewer getControl

List of usage examples for org.eclipse.jface.viewers ComboViewer getControl

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers ComboViewer getControl.

Prototype

@Override
    public Control getControl() 

Source Link

Usage

From source file:skillpro.dialogs.AddInputOutputDialog.java

License:Open Source License

private void createButtonsComposite(Composite container) {
    GridDataFactory gdf = GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).span(2, 1);

    final Label productLabel = new Label(container, SWT.NONE);
    productLabel.setText("Product: ");
    productLabel.setLayoutData(gdf.span(1, 2).create());

    Set<Product> products = new HashSet<>();
    products.addAll(SkillproService.getSkillproProvider().getProductRepo().getEntities());
    for (ProductQuantity prodQuantity : existingProductQuantities) {
        products.remove(prodQuantity.getProduct());
    }/*from  www.j  a  v  a2s.c  om*/
    final ComboViewer productComboViewer = new ComboViewer(container);
    productComboViewer.getControl().setLayoutData(gdf.span(1, 2).create());
    productComboViewer.setContentProvider(new ArrayContentProvider());
    productComboViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((Product) element).getName();
        }
    });
    productComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            product = (Product) ((IStructuredSelection) productComboViewer.getSelection()).getFirstElement();
            validate();
        }
    });
    productComboViewer.setInput(products);

    final Label quantityLabel = new Label(container, SWT.NONE);
    quantityLabel.setText("Quantity: ");
    quantityLabel.setLayoutData(gdf.span(1, 1).create());

    final Text quantityText = new Text(container, SWT.BORDER);
    quantityText.setText(String.valueOf(quantity));
    quantityText.setLayoutData(gdf.span(1, 1).create());

    final Label errorLabel = new Label(container, SWT.NONE);
    errorLabel.setText(getMessage());
    errorLabel.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_RED));
    errorLabel.setLayoutData(GridDataFactory.fillDefaults().span(2, 1).create());
    quantityText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            quantity = -1;
            try {
                quantity = Integer.parseInt(quantityText.getText());
            } catch (NumberFormatException ex) {
            }
            if (quantity <= 0) {
                setMessage("Quantity has to be a positive integer");
            } else {
                setMessage("");
            }
            errorLabel.setText(getMessage());
            validate();
        }
    });
}

From source file:skillpro.dialogs.AddRequirementPairDialog.java

License:Open Source License

private void createResourceSkillComposite(Composite parent) {
    GridDataFactory gdGrab = GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).copy().grab(true,
            false);//  w w w.j  a  v a2 s  .  c  o m
    Composite resourceSkillComposite = new Composite(parent, SWT.NONE);
    resourceSkillComposite
            .setLayout(GridLayoutFactory.fillDefaults().equalWidth(false).numColumns(2).margins(3, 4).create());
    resourceSkillComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

    Label resourceLabel = new Label(resourceSkillComposite, SWT.NONE);
    resourceLabel.setText("Resource");
    resourceLabel.setLayoutData(
            GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).grab(false, false).create());

    final ComboViewer resourceCV = new ComboViewer(resourceSkillComposite);
    resourceCV.getControl().setLayoutData(gdGrab.create());
    resourceCV.setContentProvider(new ArrayContentProvider());
    resourceCV.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((Resource) element).getName();
        }
    });
    List<Resource> resourceInput = new ArrayList<>(
            SkillproService.getSkillproProvider().getAssetRepo().getAllAssignedResources());
    for (PrePostRequirement pair : mainResourceSkill.getPrePostRequirements()) {
        //FIXME assuming that every pairs have a resource skill
        Resource existingResource = pair.getPreRequirement().getRequiredResourceSkill().getResource();
        if (selectedResource == null || !selectedResource.equals(existingResource)) {
            resourceInput.remove(existingResource);
        }
    }
    resourceCV.setInput(resourceInput);
    if (requiredResourceSkill != null) {
        resourceCV.setSelection(new StructuredSelection(selectedResource));
    } else if (resourceInput.size() > 0) {
        resourceCV.setSelection(new StructuredSelection(resourceInput.get(0)));
        selectedResource = resourceInput.get(0);
    }
    resourceCV.getControl().setEnabled(isRequiredRSkillEditable);

    Label resourceSkillLabel = new Label(resourceSkillComposite, SWT.NONE);
    resourceSkillLabel.setText("ResourceSkill");
    resourceSkillLabel.setLayoutData(
            GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).grab(false, false).create());

    final ComboViewer resourceSkillCV = new ComboViewer(resourceSkillComposite);
    resourceSkillCV.getControl().setLayoutData(gdGrab.create());
    resourceSkillCV.setContentProvider(new ArrayContentProvider());
    resourceSkillCV.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((ResourceSkill) element).getName();
        }
    });

    final List<ResourceSkill> input = new ArrayList<>();
    for (Setup setup : selectedResource.getSetups()) {
        input.addAll(setup.getResourceSkills());
    }
    if (requiredResourceSkill != null) {
        resourceSkillCV.setSelection(new StructuredSelection(requiredResourceSkill));
    } else {
        resourceSkillCV.setSelection(new StructuredSelection(input.get(0)));
        requiredResourceSkill = input.get(0);
    }
    resourceSkillCV.setInput(input);
    if (requiredResourceSkill != null) {
        resourceSkillCV.setSelection(new StructuredSelection(requiredResourceSkill));
    } else if (input.size() > 0) {
        resourceSkillCV.setSelection(new StructuredSelection(input.get(0)));
        requiredResourceSkill = input.get(0);
    }
    resourceSkillCV.getControl().setEnabled(isRequiredRSkillEditable);
    resourceSkillCV.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            requiredResourceSkill = (ResourceSkill) ((IStructuredSelection) resourceSkillCV.getSelection())
                    .getFirstElement();
            validate();
        }
    });

    resourceCV.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            selectedResource = (Resource) ((IStructuredSelection) resourceCV.getSelection()).getFirstElement();
            List<ResourceConfiguration> resourceConfigInput = selectedResource != null
                    ? new ArrayList<>(selectedResource.getResourceConfigurations())
                    : new ArrayList<ResourceConfiguration>();
            preResourceConfigCV.setInput(resourceConfigInput);

            if (resourceConfigInput.size() > 0) {
                preResourceConfigCV.setSelection(new StructuredSelection(resourceConfigInput.get(0)));
                preResourceConfiguration = resourceConfigInput.get(0);
            }

            postResourceConfigCV.setInput(resourceConfigInput);

            if (resourceConfigInput.size() > 0) {
                postResourceConfigCV.setSelection(new StructuredSelection(resourceConfigInput.get(0)));
                postResourceConfiguration = resourceConfigInput.get(0);
            }
            input.clear();
            if (selectedResource != null) {
                for (Setup setup : selectedResource.getSetups()) {
                    input.addAll(setup.getResourceSkills());
                }
            }
            resourceSkillCV.refresh();
            resourceSkillCV.setSelection(new StructuredSelection(input.get(0)));
            requiredResourceSkill = input.get(0);
            validate();
        }
    });
}

From source file:skillpro.dialogs.AddRequirementPairDialog.java

License:Open Source License

private void createSkillSyncComposite(Composite parent) {
    GridDataFactory gdGrab = GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).copy().grab(true,
            false);/* w w w .  j  ava 2s  .  c o  m*/
    Composite skillSyncComposite = new Composite(parent, SWT.NONE);
    skillSyncComposite
            .setLayout(GridLayoutFactory.fillDefaults().equalWidth(false).numColumns(2).margins(3, 4).create());
    skillSyncComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

    Label skillSyncLabel = new Label(skillSyncComposite, SWT.NONE);
    skillSyncLabel.setText("Skill Sync Type");
    skillSyncLabel.setLayoutData(
            GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).grab(false, false).create());

    final ComboViewer skillSyncCV = new ComboViewer(skillSyncComposite);
    skillSyncCV.getControl().setLayoutData(gdGrab.create());
    skillSyncCV.setContentProvider(new ArrayContentProvider());
    skillSyncCV.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((SkillSynchronizationType) element).getName();
        }
    });

    final List<SkillSynchronizationType> input = new ArrayList<>();
    for (SkillSynchronizationType type : SkillSynchronizationType.values()) {
        input.add(type);
    }
    skillSyncCV.setInput(input);

    if (syncType != null) {
        skillSyncCV.setSelection(new StructuredSelection(syncType));
    } else {
        skillSyncCV.setSelection(new StructuredSelection(SkillSynchronizationType.NONE));
        syncType = SkillSynchronizationType.NONE;
    }
    skillSyncCV.refresh();
    skillSyncCV.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            syncType = (SkillSynchronizationType) ((IStructuredSelection) skillSyncCV.getSelection())
                    .getFirstElement();
            validate();
        }
    });

}

From source file:skillpro.dialogs.AddRequirementPairDialog.java

License:Open Source License

private void createPreRequirementComposite(Composite parent) {
    GridDataFactory gdGrab = GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).copy().grab(true,
            false);//from w  w  w . j  a v  a 2  s . c o m
    Composite preRequirementComposite = new Composite(parent, SWT.NONE);
    preRequirementComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(1, 1).create());
    preRequirementComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    //center label
    Label preRequirementLabel = new Label(preRequirementComposite, SWT.NONE);
    preRequirementLabel.setText("Pre-Requirement");
    preRequirementLabel.setLayoutData(
            GridDataFactory.fillDefaults().span(2, 1).align(SWT.CENTER, SWT.CENTER).grab(true, false).create());
    //ResourceConfigurationType
    Label resourceConfigTypeLabel = new Label(preRequirementComposite, SWT.NONE);
    resourceConfigTypeLabel.setText("Resource Config Type");
    resourceConfigTypeLabel.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    final ComboViewer resourceConfigTypeCV = new ComboViewer(preRequirementComposite);
    resourceConfigTypeCV.getControl().setLayoutData(gdGrab.create());
    resourceConfigTypeCV.setContentProvider(new ArrayContentProvider());
    resourceConfigTypeCV.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((RequirementResourceConfigType) element).toString();
        }
    });
    List<RequirementResourceConfigType> resourceConfigurationTypeInput = Arrays
            .asList(RequirementResourceConfigType.values());
    resourceConfigurationTypeInput = new ArrayList<>(resourceConfigurationTypeInput);
    for (Iterator<RequirementResourceConfigType> iter = resourceConfigurationTypeInput.iterator(); iter
            .hasNext();) {
        RequirementResourceConfigType type = iter.next();
        if (type.toString().equalsIgnoreCase("different_any") || type.toString().equalsIgnoreCase("same")) {
            iter.remove();
        }
    }
    resourceConfigTypeCV.setInput(resourceConfigurationTypeInput);

    if (preResourceConfigType != null) {
        resourceConfigTypeCV.setSelection(new StructuredSelection(preResourceConfigType));
    } else if (resourceConfigurationTypeInput.size() > 0) {
        resourceConfigTypeCV.setSelection(new StructuredSelection(resourceConfigurationTypeInput.get(0)));
        preResourceConfigType = resourceConfigurationTypeInput.get(0);
    }

    //ResourceConfiguration
    Label resourceConfigurationLabel = new Label(preRequirementComposite, SWT.NONE);
    resourceConfigurationLabel.setText("Resource Configuration");
    resourceConfigurationLabel.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    preResourceConfigCV = new ComboViewer(preRequirementComposite);
    preResourceConfigCV.getControl().setLayoutData(gdGrab.create());
    preResourceConfigCV.setContentProvider(new ArrayContentProvider());
    preResourceConfigCV.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((ResourceConfiguration) element).getName();
        }
    });
    List<ResourceConfiguration> resourceConfigInput = requiredResourceSkill != null
            ? new ArrayList<>(requiredResourceSkill.getResource().getResourceConfigurations())
            : new ArrayList<ResourceConfiguration>();
    preResourceConfigCV.setInput(resourceConfigInput);

    if (preResourceConfiguration != null) {
        preResourceConfigCV.setSelection(new StructuredSelection(preResourceConfiguration));
    } else if (resourceConfigInput.size() > 0) {
        preResourceConfigCV.setSelection(new StructuredSelection(resourceConfigInput.get(0)));
        preResourceConfiguration = resourceConfigInput.get(0);
    }
    if (preResourceConfigType != RequirementResourceConfigType.SPECIFIC) {
        preResourceConfigCV.getControl().setEnabled(false);
    }

    //ProductConfigurationType
    Label productConfigurationTypeLabel = new Label(preRequirementComposite, SWT.NONE);
    productConfigurationTypeLabel.setText("Product Config Type");
    productConfigurationTypeLabel.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    final ComboViewer productConfigTypeCV = new ComboViewer(preRequirementComposite);
    productConfigTypeCV.getControl().setLayoutData(gdGrab.create());
    productConfigTypeCV.setContentProvider(new ArrayContentProvider());
    productConfigTypeCV.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((RequirementProductConfigType) element).toString();
        }
    });
    List<RequirementProductConfigType> productConfigTypeInput = Arrays
            .asList(RequirementProductConfigType.values());
    productConfigTypeInput = new ArrayList<>(productConfigTypeInput);
    for (Iterator<RequirementProductConfigType> iter = productConfigTypeInput.iterator(); iter.hasNext();) {
        RequirementProductConfigType type = iter.next();
        if (type.toString().equalsIgnoreCase("same")) {
            iter.remove();
        }
    }
    productConfigTypeCV.setInput(productConfigTypeInput);
    if (preProductConfigType != null) {
        productConfigTypeCV.setSelection(new StructuredSelection(preProductConfigType));
    } else if (productConfigTypeInput.size() > 0) {
        productConfigTypeCV.setSelection(new StructuredSelection(productConfigTypeInput.get(0)));
        preProductConfigType = productConfigTypeInput.get(0);
    }

    //ProductConfiguration
    Label ProductConfigurationLabel = new Label(preRequirementComposite, SWT.NONE);
    ProductConfigurationLabel.setText("Product Configuration");
    ProductConfigurationLabel
            .setLayoutData(GridDataFactory.fillDefaults().span(2, 1).grab(true, false).create());

    String[] headers = { "Name", "Quantity" };
    int[] bounds = { 100, 100 };

    // input
    if (preProductConfiguration != null) {
        preProductQuantities.addAll(preProductConfiguration.getProductQuantities());
    }
    final TableViewer preProductQuantitiesTableViewer = createTableViewer(preRequirementComposite, headers,
            bounds);

    preProductQuantitiesTableViewer.setInput(preProductQuantities);
    preProductQuantitiesTableViewer.getControl()
            .setLayoutData(GridDataFactory.fillDefaults().span(2, 1).grab(true, true).hint(0, 200).create());

    // ADD Buttons
    Composite inputButtonsArea = new Composite(preRequirementComposite, SWT.NONE);
    inputButtonsArea.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).create());

    Button addPreProductQuantityButton = new Button(inputButtonsArea, SWT.PUSH);
    addPreProductQuantityButton.setText("Add");
    Button deleteProductQuantityButton = new Button(inputButtonsArea, SWT.PUSH);
    deleteProductQuantityButton.setText("Delete");

    if (preProductConfigType != RequirementProductConfigType.SPECIFIC) {
        preProductQuantitiesTableViewer.getControl().setEnabled(false);
    }

    //Listeners!!
    resourceConfigTypeCV.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            preResourceConfigType = (RequirementResourceConfigType) ((IStructuredSelection) resourceConfigTypeCV
                    .getSelection()).getFirstElement();
            if (preResourceConfigType == RequirementResourceConfigType.SPECIFIC) {
                preResourceConfigCV.getControl().setEnabled(true);
                preResourceConfiguration = (ResourceConfiguration) ((IStructuredSelection) preResourceConfigCV
                        .getSelection()).getFirstElement();
            } else {
                preResourceConfigCV.getControl().setEnabled(false);
                preResourceConfiguration = null;
            }
            validate();
        }
    });

    preResourceConfigCV.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            preResourceConfiguration = (ResourceConfiguration) ((IStructuredSelection) preResourceConfigCV
                    .getSelection()).getFirstElement();
            validate();
        }
    });

    productConfigTypeCV.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            preProductConfigType = (RequirementProductConfigType) ((IStructuredSelection) productConfigTypeCV
                    .getSelection()).getFirstElement();
            if (preProductConfigType == RequirementProductConfigType.SPECIFIC) {
                preProductQuantitiesTableViewer.getControl().setEnabled(true);
            } else {
                preProductQuantitiesTableViewer.getControl().setEnabled(false);
            }
            validate();
        }
    });

    addPreProductQuantityButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            AddInputOutputDialog dialog = new AddInputOutputDialog(getShell(), ProductDialogType.INPUT_DIALOG,
                    preProductQuantities);
            if (dialog.open() == Window.OK) {
                for (ProductQuantity pq : dialog.getResult()) {
                    preProductQuantities.add(pq);
                }
                preProductQuantitiesTableViewer.refresh();
                validate();
            }

        }
    });

    deleteProductQuantityButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            deleteSelected(preProductQuantitiesTableViewer);
            preProductQuantitiesTableViewer.refresh();
            validate();

        }
    });

}

From source file:skillpro.dialogs.AddRequirementPairDialog.java

License:Open Source License

private void createPostRequirementComposite(Composite parent) {
    GridDataFactory gdGrab = GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).copy().grab(true,
            false);//  w w w  . j  av a 2 s  .c  om
    Composite postRequirementComposite = new Composite(parent, SWT.NONE);
    postRequirementComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(1, 1).create());
    postRequirementComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    //center label
    Label postRequirementLabel = new Label(postRequirementComposite, SWT.NONE);
    postRequirementLabel.setText("Post-Requirement");
    postRequirementLabel.setLayoutData(
            GridDataFactory.fillDefaults().span(2, 1).align(SWT.CENTER, SWT.CENTER).grab(true, false).create());
    //ResourceConfigurationType
    Label resourceConfigTypeLabel = new Label(postRequirementComposite, SWT.NONE);
    resourceConfigTypeLabel.setText("Resource Config Type");
    resourceConfigTypeLabel.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    final ComboViewer resourceConfigTypeCV = new ComboViewer(postRequirementComposite);
    resourceConfigTypeCV.getControl().setLayoutData(gdGrab.create());
    resourceConfigTypeCV.setContentProvider(new ArrayContentProvider());
    resourceConfigTypeCV.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((RequirementResourceConfigType) element).toString();
        }
    });
    List<RequirementResourceConfigType> resourceConfigurationTypeInput = Arrays
            .asList(RequirementResourceConfigType.values());
    resourceConfigTypeCV.setInput(resourceConfigurationTypeInput);

    if (postResourceConfigType != null) {
        resourceConfigTypeCV.setSelection(new StructuredSelection(postResourceConfigType));
    } else if (resourceConfigurationTypeInput.size() > 0) {
        resourceConfigTypeCV.setSelection(new StructuredSelection(resourceConfigurationTypeInput.get(0)));
        postResourceConfigType = resourceConfigurationTypeInput.get(0);
    }

    //ResourceConfiguration
    Label resourceConfigurationLabel = new Label(postRequirementComposite, SWT.NONE);
    resourceConfigurationLabel.setText("Resource Configuration");
    resourceConfigurationLabel.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    postResourceConfigCV = new ComboViewer(postRequirementComposite);
    postResourceConfigCV.getControl().setLayoutData(gdGrab.create());
    postResourceConfigCV.setContentProvider(new ArrayContentProvider());
    postResourceConfigCV.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((ResourceConfiguration) element).getName();
        }
    });
    List<ResourceConfiguration> resourceConfigInput = requiredResourceSkill != null
            ? new ArrayList<>(requiredResourceSkill.getResource().getResourceConfigurations())
            : new ArrayList<ResourceConfiguration>();
    postResourceConfigCV.setInput(resourceConfigInput);
    if (postResourceConfiguration != null) {
        postResourceConfigCV.setSelection(new StructuredSelection(postResourceConfiguration));

    } else if (resourceConfigInput.size() > 0) {
        postResourceConfigCV.setSelection(new StructuredSelection(resourceConfigInput.get(0)));
        postResourceConfiguration = resourceConfigInput.get(0);
    }
    if (postResourceConfigType != RequirementResourceConfigType.SPECIFIC) {
        postResourceConfigCV.getControl().setEnabled(false);
    }

    //ProductConfigurationType
    Label productConfigurationTypeLabel = new Label(postRequirementComposite, SWT.NONE);
    productConfigurationTypeLabel.setText("Product Config Type");
    productConfigurationTypeLabel.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    final ComboViewer productConfigTypeCV = new ComboViewer(postRequirementComposite);
    productConfigTypeCV.getControl().setLayoutData(gdGrab.create());
    productConfigTypeCV.setContentProvider(new ArrayContentProvider());
    productConfigTypeCV.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((RequirementProductConfigType) element).toString();
        }
    });
    List<RequirementProductConfigType> productConfigTypeInput = Arrays
            .asList(RequirementProductConfigType.values());
    productConfigTypeInput = new ArrayList<>(productConfigTypeInput);
    for (Iterator<RequirementProductConfigType> iter = productConfigTypeInput.iterator(); iter.hasNext();) {
        RequirementProductConfigType type = iter.next();
        if (type.toString().equalsIgnoreCase("any")) {
            iter.remove();
        }
    }
    productConfigTypeCV.setInput(productConfigTypeInput);

    if (postProductConfigType != null) {
        productConfigTypeCV.setSelection(new StructuredSelection(postProductConfigType));
    } else if (productConfigTypeInput.size() > 0) {
        productConfigTypeCV.setSelection(new StructuredSelection(productConfigTypeInput.get(0)));
        postProductConfigType = productConfigTypeInput.get(0);
    }

    //ProductConfiguration
    Label ProductConfigurationLabel = new Label(postRequirementComposite, SWT.NONE);
    ProductConfigurationLabel.setText("Product Configuration");
    ProductConfigurationLabel
            .setLayoutData(GridDataFactory.fillDefaults().span(2, 1).grab(true, false).create());

    String[] headers = { "Name", "Quantity" };
    int[] bounds = { 100, 100 };

    // input
    if (postProductConfiguration != null) {
        postProductQuantities.addAll(postProductConfiguration.getProductQuantities());
    }
    final TableViewer postProductQuantitiesTableViewer = createTableViewer(postRequirementComposite, headers,
            bounds);

    postProductQuantitiesTableViewer.setInput(postProductQuantities);
    postProductQuantitiesTableViewer.getControl()
            .setLayoutData(GridDataFactory.fillDefaults().span(2, 1).grab(true, true).hint(0, 200).create());

    // ADD Buttons
    Composite inputButtonsArea = new Composite(postRequirementComposite, SWT.NONE);
    inputButtonsArea.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).create());

    final Button addPostProductQuantityButton = new Button(inputButtonsArea, SWT.PUSH);
    addPostProductQuantityButton.setText("Add");
    final Button deletePostProductQuantityButton = new Button(inputButtonsArea, SWT.PUSH);
    deletePostProductQuantityButton.setText("Delete");

    if (postProductConfigType != RequirementProductConfigType.SPECIFIC) {
        postProductQuantitiesTableViewer.getControl().setEnabled(false);
    }

    //Listeners!!
    resourceConfigTypeCV.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            postResourceConfigType = (RequirementResourceConfigType) ((IStructuredSelection) resourceConfigTypeCV
                    .getSelection()).getFirstElement();
            if (postResourceConfigType == RequirementResourceConfigType.SPECIFIC) {
                postResourceConfigCV.getControl().setEnabled(true);
                postResourceConfiguration = (ResourceConfiguration) ((IStructuredSelection) postResourceConfigCV
                        .getSelection()).getFirstElement();
            } else {
                if (postResourceConfigType == RequirementResourceConfigType.SAME) {
                    if (preResourceConfiguration != null) {
                        postResourceConfigCV.setSelection(new StructuredSelection(preResourceConfiguration));
                    }
                }
                postResourceConfiguration = null;
                postResourceConfigCV.getControl().setEnabled(false);

            }
            validate();
        }
    });

    postResourceConfigCV.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            postResourceConfiguration = (ResourceConfiguration) ((IStructuredSelection) postResourceConfigCV
                    .getSelection()).getFirstElement();
            validate();
        }
    });

    productConfigTypeCV.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            postProductConfigType = (RequirementProductConfigType) ((IStructuredSelection) productConfigTypeCV
                    .getSelection()).getFirstElement();
            if (postProductConfigType == RequirementProductConfigType.SPECIFIC) {
                postProductQuantitiesTableViewer.getControl().setEnabled(true);
            } else {
                postProductQuantitiesTableViewer.getControl().setEnabled(false);
            }
            validate();
        }
    });

    addPostProductQuantityButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            AddInputOutputDialog dialog = new AddInputOutputDialog(getShell(), ProductDialogType.INPUT_DIALOG,
                    postProductQuantities);
            if (dialog.open() == Window.OK) {
                for (ProductQuantity pq : dialog.getResult()) {
                    postProductQuantities.add(pq);
                }
                postProductQuantitiesTableViewer.refresh();
                validate();
            }

        }
    });

    deletePostProductQuantityButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            deleteSelected(postProductQuantitiesTableViewer);
            postProductQuantitiesTableViewer.refresh();
            validate();

        }
    });
}

From source file:skillpro.dialogs.CreatePropertyDialog.java

License:Open Source License

private void createPropertyFieldsComposite(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(GridLayoutFactory.fillDefaults().equalWidth(false).numColumns(2).create());
    container.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

    Label nameLabel = new Label(container, SWT.NONE);
    nameLabel.setLayoutData(GridDataFactory.fillDefaults().create());
    nameLabel.setText("Property Name: ");

    final Text nameText = new Text(container, SWT.BORDER);
    nameText.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

    Label typeLabel = new Label(container, SWT.NONE);
    typeLabel.setLayoutData(GridDataFactory.fillDefaults().create());
    typeLabel.setText("Property Type: ");

    final ComboViewer propertyTypeComboViewer = new ComboViewer(container);
    propertyTypeComboViewer.getControl()
            .setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    propertyTypeComboViewer.setContentProvider(new ArrayContentProvider());
    propertyTypeComboViewer.setLabelProvider(new LabelProvider() {
        @Override/*from  www .  j av  a 2s. com*/
        public String getText(Object element) {
            return ((PropertyType) element).toString();
        }
    });

    propertyTypeComboViewer.setInput(PropertyType.values());
    if (PropertyType.values().length > 0) {
        PropertyType element = PropertyType.values()[0];
        propertyTypeComboViewer.setSelection(new StructuredSelection(element));
        propertyType = element;
    }

    Label unitLabel = new Label(container, SWT.NONE);
    unitLabel.setLayoutData(GridDataFactory.fillDefaults().create());
    unitLabel.setText("Property Unit: ");

    final Text unitText = new Text(container, SWT.BORDER);
    unitText.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

    //Listeners
    nameText.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            name = nameText.getText();
            validate();
        }
    });

    propertyTypeComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = propertyTypeComboViewer.getSelection();
            if (!selection.isEmpty()) {
                propertyType = (PropertyType) ((IStructuredSelection) selection).getFirstElement();
            }
            validate();
        }
    });

    unitText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            unit = unitText.getText();
        }
    });
}

From source file:skillpro.product.dialogs.AddTransportSkillToProductDialog.java

License:Open Source License

private void createContainerItems(Composite container, GridDataFactory gdGrab) {
    final Label nameLabel = new Label(container, SWT.NONE);
    nameLabel.setText("Name");
    final Text nameText = new Text(container, SWT.BORDER);
    nameText.setLayoutData(gdGrab.create());
    nameText.setText(name);/*from w w  w  .j  a  va 2  s . co  m*/

    final Label templateSkillLabel = new Label(container, SWT.NONE);
    templateSkillLabel.setText("Template Skill");

    final ComboViewer templateSkillCV = new ComboViewer(container);
    templateSkillCV.getControl().setLayoutData(gdGrab.create());
    templateSkillCV.setContentProvider(new ArrayContentProvider());
    templateSkillCV.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((TemplateSkill) element).getName();
        }
    });

    templateSkillCV.setInput(SkillproService.getSkillproProvider().getTemplateSkillRepo().getEntities());

    // LISTENERS
    templateSkillCV.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            skill = (TemplateSkill) ((IStructuredSelection) templateSkillCV.getSelection()).getFirstElement();
            validate();
        }
    });

    nameText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            name = nameText.getText();
            validate();
        }
    });
}

From source file:skillpro.product.dialogs.CreateProductDialog.java

License:Open Source License

private Composite createProductionSkillPage(Composite parent) {
    GridLayoutFactory gridLayoutSingle = GridLayoutFactory.swtDefaults();
    GridLayoutFactory gridLayoutDouble = GridLayoutFactory.swtDefaults().numColumns(2);
    GridDataFactory gd = GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER);
    GridDataFactory gdGrab = gd.copy().grab(true, false);

    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(gridLayoutSingle.create());

    Composite topArea = new Composite(container, SWT.NONE);
    topArea.setLayoutData(gdGrab.create());
    topArea.setLayout(gridLayoutDouble.create());

    final Label productionSkillLabel = new Label(topArea, SWT.NONE);
    productionSkillLabel.setText("Name");

    final Text productionSkillText = new Text(topArea, SWT.BORDER);
    productionSkillText.setText("");
    productionSkillText.setLayoutData(gdGrab.create());

    final Label templateSkillLabel = new Label(topArea, SWT.NONE);
    templateSkillLabel.setText("Template Skill");

    final ComboViewer templateSkillCV = new ComboViewer(topArea);
    templateSkillCV.getControl().setLayoutData(gdGrab.create());
    templateSkillCV.setContentProvider(new ArrayContentProvider());
    templateSkillCV.setLabelProvider(new LabelProvider() {
        @Override/*from  ww w.  java2  s  .c  o m*/
        public String getText(Object element) {
            return ((TemplateSkill) element).getName();
        }
    });

    templateSkillCV.setInput(SkillproService.getSkillproProvider().getTemplateSkillRepo().getEntities());
    // tables
    Composite tablesArea = new Composite(container, SWT.NONE);
    tablesArea.setLayoutData(gdGrab.create());
    tablesArea.setLayout(gridLayoutDouble.create());

    final Label inputsLabel = new Label(tablesArea, SWT.NONE);
    inputsLabel.setText("Input products:");
    inputsLabel.setLayoutData(gdGrab.create());

    final Label outputsLabel = new Label(tablesArea, SWT.NONE);
    outputsLabel.setText("Output products:");
    outputsLabel.setLayoutData(gdGrab.create());

    String[] headers = { "Name", "Quantity" };
    int[] bounds = { 150, 100 };
    // input
    inputTableViewer = createTableViewer(tablesArea, headers, bounds);
    inputTableViewer.setInput(inputs);
    // output
    outputTableViewer = createTableViewer(tablesArea, headers, bounds);
    outputTableViewer.setInput(outputs);
    // ADD Buttons
    Composite inputButtonsArea = new Composite(tablesArea, SWT.NONE);
    inputButtonsArea.setLayout(gridLayoutDouble.create());

    addInputButton = new Button(inputButtonsArea, SWT.PUSH);
    addInputButton.setText("Add");
    deleteInputButton = new Button(inputButtonsArea, SWT.PUSH);
    deleteInputButton.setText("Delete");

    Composite outputButtonsArea = new Composite(tablesArea, SWT.NONE);
    outputButtonsArea.setLayout(gridLayoutDouble.create());

    addOutputButton = new Button(outputButtonsArea, SWT.PUSH);
    addOutputButton.setText("Add");
    deleteOutputButton = new Button(outputButtonsArea, SWT.PUSH);
    deleteOutputButton.setText("Delete");

    if (modifyDialog && !isProduct) {
        this.productionSkillName = productionSkill.getName();
        for (ProductQuantity input : productionSkill.getInputConfiguration().getProductQuantities()) {
            inputs.add(input);
        }
        for (ProductQuantity output : productionSkill.getOutputConfiguration().getProductQuantities()) {
            outputs.add(output);
        }
        this.templateSkill = productionSkill.getTemplateSkill();
        productionSkillText.setText(productionSkillName);

        templateSkillCV.setSelection(new StructuredSelection(productionSkill.getTemplateSkill()));
        inputTableViewer.setInput(inputs);
        outputTableViewer.setInput(outputs);
    }
    // ADD LISTENERS
    templateSkillCV.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            templateSkill = (TemplateSkill) ((IStructuredSelection) templateSkillCV.getSelection())
                    .getFirstElement();
            validate();
        }
    });

    addInputButton.addSelectionListener(addProductQuantitySelectionListener(inputs));
    addOutputButton.addSelectionListener(addProductQuantitySelectionListener(outputs));

    deleteInputButton.addSelectionListener(deleteProductQuantityListener());
    deleteOutputButton.addSelectionListener(deleteProductQuantityListener());

    productionSkillText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            productionSkillName = productionSkillText.getText();
            validate();
        }
    });
    return container;
}

From source file:skillpro.product.dialogs.CreateProductDialog.java

License:Open Source License

private Composite createProductPage(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();

    container.setLayout(layout);// w  w  w. j  a  v  a  2 s  .com
    layout.numColumns = 2;

    GridDataFactory gd = GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER);
    GridDataFactory gdInput = gd.copy().grab(true, false);

    final Label productLabel = new Label(container, SWT.NONE);
    productLabel.setText("Name");

    final Text productText = new Text(container, SWT.BORDER);
    productText.setText("");
    productText.setLayoutData(gdInput.create());

    final Label supplyLabel = new Label(container, SWT.NONE);
    supplyLabel.setText("Supply");

    //FIXME Supply and Supplier are both not used for now
    final Text supplyText = new Text(container, SWT.BORDER);
    supplyText.setText("");
    supplyText.setLayoutData(gdInput.create());
    supplyText.setEnabled(false);

    final Label supplierLabel = new Label(container, SWT.NONE);
    supplierLabel.setText("Supplier");

    final Text supplierText = new Text(container, SWT.BORDER);
    supplierText.setText("");
    supplierText.setLayoutData(gdInput.create());
    supplierText.setEnabled(false);

    final Label factoryLabel = new Label(container, SWT.NONE);
    factoryLabel.setText("Factory");

    final ComboViewer factoryCV = new ComboViewer(container);
    factoryCV.getControl().setLayoutData(gdInput.create());
    factoryCV.setContentProvider(new ArrayContentProvider());
    factoryCV.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((Factory) element).getName();
        }
    });
    List<Factory> factories = new ArrayList<>();
    for (FactoryNode fn : SkillproService.getSkillproProvider().getAssetRepo()) {
        if (fn instanceof Factory) {
            factories.add((Factory) fn);
        }
    }
    factoryCV.setInput(factories);
    if (factories.size() > 0) {
        factory = factories.get(0);
        factoryCV.setSelection(new StructuredSelection(factory));
    }
    factoryCV.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            factory = (Factory) ((IStructuredSelection) factoryCV.getSelection()).getFirstElement();
        }
    });

    final Button disposableButton = new Button(container, SWT.CHECK);
    disposableButton.setText("Disposable");
    disposableButton.setSelection(false);
    disposableButton.setEnabled(true);

    final Button purchasableButton = new Button(container, SWT.CHECK);
    purchasableButton.setText("Purchasable");
    purchasableButton.setSelection(false);
    purchasableButton.setEnabled(true);

    if (modifyDialog && isProduct) {
        productName = product.getName();
        supplyName = product.getSupply() != null ? product.getSupply().getName() : "";
        supplierName = product.getSupply() != null && product.getSupply().getSupplier() != null
                ? product.getSupply().getSupplier().getName()
                : "";
        factory = product.getFactory();
        disposable = product.isDisposable();
        purchasable = product.isPurchasable();
        productText.setText(productName);
        supplyText.setText(supplyName);
        supplierText.setText(supplierName);
        factoryCV.setSelection(new StructuredSelection(factory));
        disposableButton.setSelection(disposable);
        purchasableButton.setSelection(purchasable);
    }

    //Listeners
    ModifyListener modifyHandler = new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            Text source = (Text) e.getSource();
            if (source == productText) {
                productName = source.getText();
            } else if (source == supplyText) {
                supplyName = source.getText();
            } else if (source == supplierText) {
                supplierName = source.getText();
            }
            validate();

        }
    };
    productText.addModifyListener(modifyHandler);
    supplyText.addModifyListener(modifyHandler);
    supplierText.addModifyListener(modifyHandler);

    SelectionListener selectionHandler = new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            Object source = e.getSource();
            if (source == disposableButton) {
                disposable = disposableButton.getSelection();
            } else if (source == purchasableButton) {
                purchasable = purchasableButton.getSelection();
            }
        }
    };
    disposableButton.addSelectionListener(selectionHandler);
    purchasableButton.addSelectionListener(selectionHandler);
    return container;
}

From source file:skillpro.view.impl.CreateSEEComposite.java

License:Open Source License

private void createConnectionComposite(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).create());
    container.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    final Label amsComLabel = new Label(container, SWT.NONE);
    amsComLabel.setText("AMS Communication: ");
    amsComLabel.setLayoutData(buttonGD.span(2, 1).create());

    final ComboViewer amsComCV = new ComboViewer(container);
    amsComCV.getControl().setLayoutData(buttonGD.span(1, 1).create());
    amsComCV.setContentProvider(new ArrayContentProvider());
    amsComCV.setLabelProvider(new LabelProvider() {
        @Override/*from  ww  w  .  jav a 2 s.c  o  m*/
        public String getText(Object element) {
            return ((AMSCommType) element).toString();
        }
    });

    amsComCV.setInput(AMSCommType.values());
    if (AMSCommType.values().length > 0) {
        AMSCommType element = AMSCommType.values()[0];
        amsComCV.setSelection(new StructuredSelection(element));
        if (amsCommunication == null) {
            amsCommunication = new Pair<AMSCommType, String>(element, null);
        } else {
            amsCommunication.setFirstElement(element);
        }
    }

    final Text amsComText = new Text(container, SWT.BORDER);
    if (amsCommunication != null && amsCommunication.getFirstElement() == AMSCommType.WEBSERVICES
            && amsCommunication.getSecondElement() == null) {
        String serviceAddress = AMSServiceUtility.serviceAddress;
        amsComText.setText(serviceAddress);
        amsCommunication.setSecondElement(serviceAddress);
    } else {
        amsComText.setText("");
    }
    amsComText.setLayoutData(buttonGD.span(1, 1).create());

    final Label mesComLabel = new Label(container, SWT.NONE);
    mesComLabel.setText("MES Communication: ");
    mesComLabel.setLayoutData(buttonGD.span(2, 1).create());

    final ComboViewer mesComCV = new ComboViewer(container);
    mesComCV.getControl().setLayoutData(buttonGD.span(1, 1).create());
    mesComCV.setContentProvider(new ArrayContentProvider());
    mesComCV.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((MESCommType) element).toString();
        }
    });

    mesComCV.setInput(MESCommType.values());
    if (MESCommType.values().length > 0) {
        MESCommType element = MESCommType.values()[0];
        mesComCV.setSelection(new StructuredSelection(element));
        if (mesCommunication == null) {
            mesCommunication = new Pair<MESCommType, String>(element, null);
        } else {
            mesCommunication.setFirstElement(element);
        }
    }

    final Text mesComText = new Text(container, SWT.BORDER);
    if (mesCommunication != null && mesCommunication.getFirstElement() == MESCommType.OPCUA
            && mesCommunication.getSecondElement() == null) {
        String serviceAddress = OPCUAServerRepository.getSelectedServerUri();
        mesComText.setText(serviceAddress);
        mesCommunication.setSecondElement(serviceAddress);
    } else {
        mesComText.setText("");
    }
    mesComText.setLayoutData(buttonGD.span(1, 1).create());

    final Label esComLabel = new Label(container, SWT.NONE);
    esComLabel.setText("ES Communication: ");
    esComLabel.setLayoutData(buttonGD.span(2, 1).create());

    final ComboViewer esComCV = new ComboViewer(container);
    esComCV.getControl().setLayoutData(buttonGD.span(1, 1).create());
    esComCV.setContentProvider(new ArrayContentProvider());
    esComCV.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((ESCommType) element).toString();
        }
    });

    esComCV.setInput(ESCommType.values());
    if (ESCommType.values().length > 0) {
        ESCommType element = ESCommType.values()[0];
        esComCV.setSelection(new StructuredSelection(element));
        if (esCommunication == null) {
            esCommunication = new Pair<ESCommType, String>(element, null);
        } else {
            esCommunication.setFirstElement(element);
        }
    }

    final Text esComText = new Text(container, SWT.BORDER);
    esComText.setText("");
    esComText.setLayoutData(buttonGD.span(1, 1).create());

    if (amsCommunication != null) {
        AMSCommType amsFirstElement = amsCommunication.getFirstElement();
        if (amsFirstElement != null) {
            amsComCV.setSelection(new StructuredSelection(amsFirstElement));
        }
        String amsSecondElement = amsCommunication.getSecondElement();
        if (amsSecondElement != null) {
            amsComText.setText(amsSecondElement);
        }
    }

    if (mesCommunication != null) {
        MESCommType firstElement = mesCommunication.getFirstElement();
        if (firstElement != null) {
            mesComCV.setSelection(new StructuredSelection(firstElement));
        }
        String secondElement = mesCommunication.getSecondElement();
        if (secondElement != null) {
            mesComText.setText(secondElement);
        }
    }

    if (esCommunication != null) {
        ESCommType firstElement = esCommunication.getFirstElement();
        if (firstElement != null) {
            esComCV.setSelection(new StructuredSelection(firstElement));
        }
        String secondElement = esCommunication.getSecondElement();
        if (secondElement != null) {
            esComText.setText(secondElement);
        }
    }

    //Listeners
    mesComCV.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = mesComCV.getSelection();
            if (!selection.isEmpty()) {
                MESCommType selectedElement = (MESCommType) ((IStructuredSelection) selection)
                        .getFirstElement();
                if (mesCommunication == null) {
                    mesCommunication = new Pair<MESCommType, String>(selectedElement, null);
                } else {
                    mesCommunication.setFirstElement(selectedElement);
                }
            }
            validate();
        }
    });

    mesComText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            if (mesCommunication == null) {
                mesCommunication = new Pair<MESCommType, String>(null, mesComText.getText());
            } else {
                mesCommunication.setSecondElement(mesComText.getText());
            }
            validate();
        }
    });

    esComCV.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = esComCV.getSelection();
            if (!selection.isEmpty()) {
                ESCommType selectedElement = (ESCommType) ((IStructuredSelection) selection).getFirstElement();
                if (esCommunication == null) {
                    esCommunication = new Pair<ESCommType, String>(selectedElement, null);
                } else {
                    esCommunication.setFirstElement(selectedElement);
                }
            }
            validate();
        }
    });

    esComText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            if (esCommunication == null) {
                esCommunication = new Pair<ESCommType, String>(null, esComText.getText());
            } else {
                esCommunication.setSecondElement(esComText.getText());
            }
            validate();
        }
    });

    amsComCV.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = amsComCV.getSelection();
            if (!selection.isEmpty()) {
                AMSCommType selectedElement = (AMSCommType) ((IStructuredSelection) selection)
                        .getFirstElement();
                if (amsCommunication == null) {
                    amsCommunication = new Pair<AMSCommType, String>(selectedElement, null);
                } else {
                    amsCommunication.setFirstElement(selectedElement);
                }
            }
            validate();
        }
    });

    amsComText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            if (amsCommunication == null) {
                amsCommunication = new Pair<AMSCommType, String>(null, amsComText.getText());
            } else {
                amsCommunication.setSecondElement(amsComText.getText());
            }
            validate();
        }
    });
}