private void open(IFile file) {
    IWorkbenchWindow dw = FMUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
    IWorkbenchPage page = dw.getActivePage();
    if (page != null) {
      IContentType contentType = null;
      try {
        IContentDescription description = file.getContentDescription();
        if (description != null) {
          contentType = description.getContentType();
        }
        IEditorDescriptor desc = null;
        if (contentType != null) {
          desc =
              PlatformUI.getWorkbench()
                  .getEditorRegistry()
                  .getDefaultEditor(file.getName(), contentType);
        } else {
          desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
        }

        if (desc != null) {
          page.openEditor(new FileEditorInput(file), desc.getId());
        }
      } catch (CoreException e) {
        FMUIPlugin.getDefault().logError(e);
      }
    }
  }
  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;
  }
 protected boolean errorMessage(Tree tree) {
   if (configurationEditor.getConfiguration() == null) {
     if (configurationEditor.getModelFile() == null) {
       displayError(
           tree,
           THERE_IS_NO_FEATURE_MODEL_CORRESPONDING_TO_THIS_CONFIGURATION_COMMA__REOPEN_THE_EDITOR_AND_SELECT_ONE_);
     } else if (!configurationEditor.getModelFile().exists()) {
       displayError(
           tree,
           THE_GIVEN_FEATURE_MODEL
               + configurationEditor.getModelFile().getPath()
               + DOES_NOT_EXIST_);
     } else {
       displayError(tree, AN_UNKNOWN_ERROR_OCCURRED_);
     }
     return false;
   } else {
     final FeatureModelAnalyzer analyzer =
         configurationEditor.getConfiguration().getFeatureModel().getAnalyser();
     try {
       if (!analyzer.isValid()) {
         displayError(
             tree,
             THE_FEATURE_MODEL_FOR_THIS_PROJECT_IS_VOID_COMMA__I_E__COMMA__THERE_IS_NO_VALID_CONFIGURATION__YOU_NEED_TO_CORRECT_THE_FEATURE_MODEL_BEFORE_YOU_CAN_CREATE_OR_EDIT_CONFIGURATIONS_);
         return false;
       }
     } catch (TimeoutException e) {
       FMUIPlugin.getDefault().logError(e);
     }
   }
   return true;
 }
 @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);
   }
 }
Exemplo n.º 5
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);
    }
  }
 private void displayError(Tree tree, String message) {
   tree.removeAll();
   TreeItem item = new TreeItem(tree, 1);
   item.setText(message);
   item.setImage(
       0,
       FMUIPlugin.getDefault()
           .getWorkbench()
           .getSharedImages()
           .getImage(ISharedImages.IMG_OBJS_ERROR_TSK));
   item.setChecked(true);
   item.setGrayed(true);
   dirty = false;
 }