public boolean performFinish() {
    FeatureModel featureModel = new FeatureModel();
    featureModel.createDefaultValues("");

    Path fullFilePath = new Path(page.fileName.getText());
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IPath rootPath = root.getLocation();
    if (rootPath.isPrefixOf(fullFilePath)) {
      // case: is file in workspace
      int matchingFirstSegments = rootPath.matchingFirstSegments(fullFilePath);
      IPath localFilePath = fullFilePath.removeFirstSegments(matchingFirstSegments);
      String[] segments = localFilePath.segments();
      localFilePath = new Path("");
      for (String segment : segments) {
        localFilePath = localFilePath.append(segment);
      }
      IFile file = root.getFile(localFilePath);
      featureModel.initFMComposerExtension(file.getProject());
      try {
        new FeatureModelWriterIFileWrapper(new XmlFeatureModelWriter(featureModel))
            .writeToFile(file);
        file.refreshLocal(IResource.DEPTH_INFINITE, null);
      } catch (CoreException e) {
        FMUIPlugin.getDefault().logError(e);
      }
      open(file);
    } else {
      // case: is no file in workspace
      File file = fullFilePath.toFile();
      new XmlFeatureModelWriter(featureModel).writeToFile(file);
    }
    return true;
  }
Ejemplo n.º 2
0
 private Set<String> calculateAddedFeatures(FeatureModel oldModel, FeatureModel newModel) {
   Set<String> addedFeatures = new HashSet<String>();
   for (Feature feature : newModel.getFeatures())
     if (feature.isConcrete()) {
       String name = newModel.getRenamingsManager().getOldName(feature.getName());
       Feature associatedFeature =
           oldModel.getFeature(oldModel.getRenamingsManager().getNewName(name));
       if (associatedFeature == null || associatedFeature.isAbstract()) addedFeatures.add(name);
     }
   return addedFeatures;
 }
 @Override
 public void run() {
   if (featureModel.getAnalyser().calculateTautologyConstraints) {
     featureModel.getAnalyser().calculateTautologyConstraints = false;
   } else {
     featureModel.getAnalyser().calculateTautologyConstraints = true;
     // featureModel.getAnalyser().calculateRedundantConstraints = true;
     featureModel.getAnalyser().calculateFeatures = true;
     featureModel.getAnalyser().calculateConstraints = true;
   }
   featureModel.handleModelDataChanged();
 }
Ejemplo n.º 4
0
 /**
  * Add constraint
  *
  * @param featureModel
  * @param constraint
  */
 public static void addConstraint(FeatureModel featureModel, String constraint) {
   NodeReader nodeReader = new NodeReader();
   List<String> featureList = new ArrayList<String>(featureModel.getFeatureNames());
   Node node = null;
   try {
     node = nodeReader.stringToNode(constraint, featureList);
   } catch (Exception e) {
     System.out.println("Not valid constraint definition: " + constraint);
   }
   // TODO report error if node is null
   if (node != null) {
     Constraint c = new Constraint(featureModel, node);
     featureModel.addConstraint(c);
   } else {
     System.out.println("Maybe problems with names: " + constraint);
   }
 }
 @Override
 public void run() {
   LayoutSelectionOperation op =
       new LayoutSelectionOperation(
           featureModel, newSelectedLayoutAlgorithm, oldSelectedLayoutAlgorithm);
   op.addContext((IUndoContext) featureModel.getUndoContext());
   try {
     PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, null, null);
   } catch (ExecutionException e) {
     FMUIPlugin.getDefault().logError(e);
   }
 }
  /**
   * use {@link GraphicalViewerKeyHandler} first if auto-layout is active handles the searching on
   * the graph (depth-first, same way as in Outline)
   */
  @Override
  public boolean keyPressed(KeyEvent e) {
    if (Character.isISOControl(e.character)) {
      if (featureModel.getLayout().hasFeaturesAutoLayout()) {
        return gvKeyHandler.keyPressed(e);
      } else {
        return super.keyPressed(e);
      }
    }

    final long currentTime = System.currentTimeMillis();
    if (currentTime - lastTime > timeoutThreshold) {
      curSearchString = "";
    }
    lastTime = currentTime;

    curIndex = updateIterator();

    if (curSearchString.length() == 1
        && curSearchString.charAt(0) == Character.toLowerCase(e.character)) {
      curSearchString = "";
      curIndex = (curIndex + 1) % featureList.size();
    }
    curSearchString += Character.toLowerCase(e.character);

    final int foundIndex = search();
    if (foundIndex >= 0) {
      // select the new feature
      final Feature curFeature = featureModel.getFeature(featureList.get(foundIndex));
      if (curFeature != null) {
        FeatureEditPart part = (FeatureEditPart) viewer.getEditPartRegistry().get(curFeature);
        viewer.setSelection(new StructuredSelection(part));
        viewer.reveal(part);
        curIndex = foundIndex;
      }
    }

    return true;
  }
Ejemplo n.º 7
0
  @Override
  public void run() {
    FeatureChangeGroupTypeOperation op =
        new FeatureChangeGroupTypeOperation(
            FeatureChangeGroupTypeOperation.AND, feature, featureModel);
    op.addContext((IUndoContext) featureModel.getUndoContext());

    try {
      PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, null, null);
    } catch (ExecutionException e) {
      FMUIPlugin.getDefault().logError(e);
    }
  }
Ejemplo n.º 8
0
 public static List<Feature> getFeatureRequiredFeatures(
     FeatureModel fm, List<IConstraint> constraints, Feature f1) {
   List<Feature> required = new ArrayList<Feature>();
   for (IConstraint constraint : constraints) {
     if (constraint.getType().equals(IConstraint.REQUIRES)) {
       if (f1.getName()
           .equals(FeatureIDEUtils.validFeatureName(constraint.getBlock1().getName()))) {
         required.add(
             fm.getFeature(FeatureIDEUtils.validFeatureName(constraint.getBlock2().getName())));
       }
     }
   }
   return required;
 }
  /**
   * alternativeKeyHandler handles the KeyEvents, if the GraphicalViewerKeyHandler is active for
   * auto-layout
   */
  public FeatureDiagramEditorKeyHandler(FeatureDiagramEditor view, FeatureModel featureModel) {
    super();

    this.featureModel = featureModel;
    this.viewer = view;

    this.alternativeKeyHandler = new KeyHandler();
    this.gvKeyHandler = new GraphicalViewerKeyHandler(view);
    this.gvKeyHandler.setParent(alternativeKeyHandler);
    this.setParent(gvKeyHandler);
    this.lastTime = 0;

    resetFeatureList();
    featureModel.addListener(this);
  }
 private void resetFeatureList() {
   featureList.clear();
   featureList.addAll(featureModel.getFeatureNamesPreorder());
   curSearchString = "";
   curIndex = 0;
 }
 public TautologyContraintsCalculationsAction(
     GraphicalViewerImpl viewer, FeatureModel featureModel) {
   super(CALCULATE_TAUTOLOGY_CONSTRAINTS);
   this.featureModel = featureModel;
   setChecked(featureModel.getAnalyser().calculateTautologyConstraints);
 }