private void getComboAttribute(Composite composite) {
    comboAttribute = new Combo(composite, SWT.READ_ONLY);
    comboAttribute.setText(Messages.getString("UpdateAttributeDialog.3")); // $NON-NLS-1$
    comboAttribute.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));

    Object firstElement = selection.get(0);
    if (firstElement instanceof EObject) {
      AttributeConfiguration configuration =
          RequirementUtils.getAttributeConfiguration(((EObject) firstElement).eResource());

      List<String> labelList = new ArrayList<String>();
      for (ConfiguratedAttribute anAttribute : configuration.getListAttributes()) {
        labelList.add(anAttribute.getName());
        comboAttribute.setData(anAttribute.getName(), anAttribute.getListValue());
      }

      comboAttribute.setItems(labelList.toArray(new String[0]));
      comboAttribute.addSelectionListener(new AttributeSelectionListener());
      comboAttribute.addModifyListener(
          new ModifyListener() {
            public void modifyText(ModifyEvent event) {
              attributeNameModified();
            }
          });
    }
  }
Ejemplo n.º 2
0
 /**
  * @see
  *     org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
  */
 public Object execute(ExecutionEvent event) throws ExecutionException {
   IEditorPart editor = RequirementUtils.getCurrentEditor();
   IEditorServices services = SupportingEditorsManager.getInstance().getServices(editor);
   if (services != null) {
     EditingDomain domain = services.getEditingDomain(editor);
     CommandStack stack = domain.getCommandStack();
     if (stack.getUndoCommand() != null) {
       stack.undo();
     }
   }
   return null;
 }
  /**
   * @see
   *     org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
   */
  public Object execute(ExecutionEvent event) throws ExecutionException {
    toSelect = new ArrayList<EObject>();
    IEditorPart editor = RequirementUtils.getCurrentEditor();
    IEditorServices services = SupportingEditorsManager.getInstance().getServices(editor);
    CurrentPage page = RequirementHelper.INSTANCE.getCurrentPage();

    if (services != null
        && ((EvaluationContext) event.getApplicationContext()).getDefaultVariable()
            instanceof List<?>) {
      EditingDomain editingDomain = services.getEditingDomain(editor);
      // Get the current selection
      List<?> elements =
          ((List<?>) ((EvaluationContext) event.getApplicationContext()).getDefaultVariable());
      CompoundCommand compoundCmd =
          new CompoundCommand(Messages.getString("AddAttributeHandler.1")); // $NON-NLS-1$
      for (Object currObject : elements) {
        EObject parent = null;
        if (currObject instanceof Attribute) {
          parent = ((Attribute) currObject).eContainer();
          int newIndex = calculateIndex(parent, (EObject) currObject);

          Attribute toDuplicate = null;
          if (currObject instanceof AttributeLink) {
            toDuplicate =
                RequirementHelper.INSTANCE.duplicateAttributeLink((AttributeLink) currObject);
          } else if (currObject instanceof ObjectAttribute) {
            toDuplicate =
                RequirementHelper.INSTANCE.duplicateObjectAttribute((ObjectAttribute) currObject);
          }
          if (parent != null && toDuplicate != null) {
            toSelect.add(toDuplicate);
            compoundCmd.appendIfCanExecute(
                AddCommand.create(
                    editingDomain,
                    parent,
                    RequirementPackage.eINSTANCE.getRequirement_Attribute(),
                    toDuplicate,
                    newIndex));
          }
        }
      }
      if (!compoundCmd.isEmpty() && compoundCmd.canExecute()) {
        editingDomain.getCommandStack().execute(compoundCmd);
        page.setSelection(new StructuredSelection(toSelect));
      }
    }
    return null;
  }
 /** @see org.eclipse.jface.viewers.IFilter#select(java.lang.Object) */
 public boolean select(Object toTest) {
   if (toTest instanceof TextAttribute) {
     TextAttribute attribute = (TextAttribute) toTest;
     AttributeConfiguration configuration =
         RequirementUtils.getAttributeConfiguration(attribute.eResource());
     if (configuration != null) {
       for (ConfiguratedAttribute att : configuration.getListAttributes()) {
         if (AttributesType.TEXT.equals(att.getType())
             && attribute.getName().equals(att.getName())) {
           return att.getListValue().isEmpty();
         }
       }
     } else {
       return true;
     }
   }
   return false;
 }
    @SuppressWarnings("unchecked")
    public void widgetSelected(SelectionEvent e) {
      EObject currObject = (EObject) selection.get(0);
      listEObjects = new ArrayList<EObject>();

      if (currObject instanceof Requirement) {
        Attribute attribute =
            CurrentPreferenceHelper.getAttribute(
                (Requirement) currObject, comboAttribute.getText());
        EList<AttributeValue> values =
            (EList<AttributeValue>) comboAttribute.getData(comboAttribute.getText());

        if (attribute instanceof TextAttribute && values.size() > 0) {
          comboValue.setEnabled(true);
          textValue.setEnabled(false);
          Collection<String> choice =
              CurrentPreferenceHelper.getTextualValues((TextAttribute) attribute);
          comboValue.setItems(choice.toArray(new String[0]));
          comboValue.setSelection(new Point(0, comboValue.getText().length()));
        } else if (attribute instanceof AttributeAllocate) {
          comboValue.setEnabled(true);
          textValue.setEnabled(false);
          listEObjects.addAll(
              RequirementUtils.getAllObjects(EcorePackage.eINSTANCE.getEModelElement()));
          comboValue.setItems(listToArray(listEObjects));
          comboValue.setSelection(new Point(0, comboValue.getText().length()));
        } else if (attribute instanceof AttributeLink) {
          comboValue.setEnabled(true);
          textValue.setEnabled(false);
          listEObjects.addAll(RequirementUtils.getAllUpstreams(currObject.eResource()));
          listEObjects.addAll(RequirementUtils.getAllCurrents(currObject.eResource()));
          comboValue.setItems(listToArray(listEObjects));
          comboValue.setSelection(new Point(0, comboValue.getText().length()));
        } else if (attribute instanceof ObjectAttribute) {
          comboValue.setEnabled(true);
          textValue.setEnabled(false);
          listEObjects.addAll(RequirementUtils.getAllUpstreams(currObject.eResource()));
          listEObjects.addAll(RequirementUtils.getAllCurrents(currObject.eResource()));
          listEObjects.addAll(
              RequirementUtils.getAllObjects(EcorePackage.eINSTANCE.getEModelElement()));
          comboValue.setItems(listToArray(listEObjects));
          comboValue.setSelection(new Point(0, comboValue.getText().length()));
        } else {
          comboValue.setEnabled(false);
          textValue.setEnabled(true);
          comboValue.setItems(new String[0]);
        }
      }
    }
 /**
  * Initializes the target Hierarchical Element. This method is executed only one time per Command.
  */
 private void initializeTarget() {
   targetElt = RequirementUtils.getHierarchicalElementFor(target);
   if (targetElt == null) {
     targetElt = RequirementHelper.INSTANCE.getHierarchicalElement(target, this);
   }
 }