コード例 #1
0
  private DiagramRoot getElement(TransactionalEditingDomain editingDomain) {
    String wrProjectPath = diagramRoot.getProjectPath();
    String projectName = wrProjectPath.substring(wrProjectPath.lastIndexOf("/") + 1);
    String fileName =
        variativitySelectionPage.getText() + "." + projectName + ProjectPlweb.PLWEB_EXTENSION;

    IPath filePath = new Path(PathHelper.getProjectFile(projectName, fileName));
    IFile fileHandle = ResourcesPlugin.getWorkspace().getRoot().getFile(filePath);
    URI uri = URI.createPlatformResourceURI(fileHandle.getFullPath().toString(), true);

    ResourceSet resourceSet = editingDomain.getResourceSet();
    EObject element = null;
    try {
      Resource resource = resourceSet.getResource(uri, true);
      element = (EObject) resource.getContents().get(0);
    } catch (WrappedException ex) {
      PlwebDiagramEditorPlugin.getInstance()
          .logError("Unable to load resource: " + uri, ex); // $NON-NLS-1$
    }
    if (element == null || !(element instanceof DiagramRoot)) {
      MessageDialog.openError(
          getShell(),
          Messages.AddProduct_ResourceErrorDialogTitle,
          Messages.AddProduct_ResourceErrorDialogMessage);
      return null;
    }
    DiagramRoot diagramRoot = (DiagramRoot) element;
    return diagramRoot;
  }
コード例 #2
0
  private IFile createNewFile() {
    String wrProjectPath = diagramRoot.getProjectPath();
    String projectName = wrProjectPath.substring(wrProjectPath.lastIndexOf("/") + 1);
    String fileName =
        variativitySelectionPage.getText()
            + "."
            + projectName
            + ProjectPlweb.PLWEB_DIAGRAM_EXTENSION;

    IPath newFilePath = new Path(PathHelper.getProjectFile(projectName, fileName));
    IFile newFileHandle = ResourcesPlugin.getWorkspace().getRoot().getFile(newFilePath);
    InputStream contents = new ByteArrayInputStream(new byte[0]);
    try {
      newFileHandle.create(contents, false, null);
    } catch (CoreException e) {
      // TODO: handle exception
    }
    try {
      ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
    } catch (CoreException e) {
      // do nothing
    }
    return newFileHandle;
  }