public void addSelectedFilesToTargetList() {
    ISelection selection = sourceFileViewer.getSelection();

    if (isValidSourceFileViewerSelection(selection)) {
      java.util.List list = null;
      if (selection instanceof IStructuredSelection) {
        list = ((IStructuredSelection) selection).toList();

        if (list != null) {
          list = ((IStructuredSelection) selection).toList();
          for (Iterator i = list.iterator(); i.hasNext(); ) {
            IResource resource = (IResource) i.next();
            if (resource instanceof IFile) {
              // Check if its in the list. Don't add it if it is.
              String resourceName = resource.getFullPath().toString();
              if (selectedListBox.indexOf(resourceName) == -1) selectedListBox.add(resourceName);
            }
          }
          setFiles(selectedListBox.getItems());
        }

        setAddButtonEnabled(false);

        if (selectedListBox.getItemCount() > 0) {
          removeAllButton.setEnabled(true);
          if (isFileMandatory) setPageComplete(true);
          if (selectedListBox.getSelectionCount() > 0) setRemoveButtonEnabled(true);
          else setRemoveButtonEnabled(false);
        }
      }
    }
  }
  /** Ensures that controls are correctly set. */
  private void dialogChanged() {
    IResource resource =
        ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(getContainerName()));
    if (resource == null) {
      updateStatus("File container must be specified");
      return;
    }
    IContainer container = (IContainer) resource;
    String fileName = getFileName();
    String author = getAuthor();
    String titleName = getModelName();

    final IFile modelfile = container.getFile(new Path("models/" + fileName));
    final IFile htmlfile = container.getFile(new Path("doc/" + titleName + ".html"));

    if (getContainerName().length() == 0) {
      updateStatus("File container must be specified");
      return;
    }
    if ((resource.getType() & (IResource.PROJECT | IResource.FOLDER)) == 0) {
      updateStatus("File container must exist");
      return;
    }
    if (!resource.isAccessible()) {
      updateStatus("Project must be writable");
      return;
    }
    if (fileName.length() == 0) {
      updateStatus("File name must be specified");
      return;
    }
    if (fileName.replace('\\', '/').indexOf('/', 1) > 0) {
      updateStatus("File name must be valid");
      return;
    }
    if (!fileName.endsWith(".gaml")) {
      updateStatus("File extension must be \".gaml\"");
      return;
    }
    if (author.length() == 0) {
      updateStatus("Author name must be specified");
      return;
    }
    if (modelfile.exists()) {
      updateStatus("File already exists");
      return;
    }
    if (htmlfile.exists()) {
      updateStatus("Model name already defined");
      return;
    }

    if (titleName.length() == 0) {
      updateStatus("Model name must be specified");
      return;
    }
    updateStatus(null);
  }
Example #3
0
 /**
  * The worker method. It will find the container, create the file if missing or just replace its
  * contents, and open the editor on the newly created file.
  */
 private void doFinish(String containerName, String fileName, IProgressMonitor monitor)
     throws CoreException {
   // create a sample file
   monitor.beginTask("Creating " + fileName, 2);
   IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
   IResource resource = root.findMember(new Path(containerName));
   if (!resource.exists() || !(resource instanceof IContainer)) {
     throwCoreException("Container \"" + containerName + "\" does not exist.");
   }
   IContainer container = (IContainer) resource;
   final IFile file = container.getFile(new Path(fileName));
   try {
     InputStream stream = openContentStream();
     if (file.exists()) {
       file.setContents(stream, true, true, monitor);
     } else {
       file.create(stream, true, monitor);
     }
     stream.close();
   } catch (IOException e) {
   }
   monitor.worked(1);
   monitor.setTaskName("Opening file for editing...");
   getShell()
       .getDisplay()
       .asyncExec(
           new Runnable() {
             public void run() {
               IWorkbenchPage page =
                   PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
               try {
                 IDE.openEditor(page, file, true);
               } catch (PartInitException e) {
               }
             }
           });
   monitor.worked(1);
 }