private String formatFileName(String fileName) {
    String formatFile = null;

    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IResource resource = root.findMember(fileName);

    if (resource == null) {
      return fileName;
    }

    basePath = getBasePath(resource.getProject());
    if (basePath == null && resource.getProject() != null)
      basePath = resource.getProject().getName();
    else if (basePath == null && resource.getProject() == null) {
      basePath = ""; // $NON-NLS-1$
    }

    int type = resource.getType();
    if (type == IResource.FILE || type == IResource.FOLDER) {

      formatFile =
          basePath
              + "/" //$NON-NLS-1$
              + resource.getFullPath().removeFirstSegments(1).toString();
    } else {
      formatFile = basePath + "/"; // $NON-NLS-1$
    }
    if (!formatFile.startsWith("/")) { // $NON-NLS-1$
      formatFile = basePath + "/" + formatFile; // $NON-NLS-1$
    }
    return formatFile;
  }
  /** 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);
  }
 // parameter isFileMandatory is used to determine if at least one file must be selected
 // before being able to proceed to the next page
 public SelectMultiFilePage(
     IWorkbench workbench, IStructuredSelection selection, boolean isFileMandatory) {
   super("SelectMultiFilePage");
   this.workbench = workbench;
   this.selection = selection;
   this.isFileMandatory = isFileMandatory;
   this.workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
   this.fileNames = null;
 }
 public void setVisible(boolean visible) {
   if (visible == true) {
     if (fFilters != null) {
       sourceFileViewer.resetFilters();
       for (Iterator i = fFilters.iterator(); i.hasNext(); )
         sourceFileViewer.addFilter((ViewerFilter) i.next());
     }
     sourceFileViewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
   }
   super.setVisible(visible);
 }
  protected IProject getProject(String name) {
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IProject[] projects = workspaceRoot.getProjects();

    if (projects == null || projects.length == 0) return null;

    for (IProject project : projects) {
      if (project.getName().equals(name)) return project;
    }

    return null;
  }
 /**
  * Uses the standard container selection dialog to choose the new value for the container field.
  */
 private void handleBrowse() {
   ContainerSelectionDialog dialog =
       new ContainerSelectionDialog(
           getShell(),
           ResourcesPlugin.getWorkspace().getRoot(),
           false,
           "Select a project as a container");
   if (dialog.open() == Window.OK) {
     Object[] result = dialog.getResult();
     if (result.length == 1) {
       containerText.setText(((Path) result[0]).toString());
     }
   }
 }
  /** @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(ILaunchConfiguration) */
  public boolean isValid(ILaunchConfiguration launchConfig) {
    setMessage(null);
    setErrorMessage(null);
    // TODO - Note that this method of removing invalid launches is still
    // buggy
    // In order to fix it completely, we might have to perform similar
    // checks when removing or renaming a server from
    // the PHP Servers preferences page.
    try {
      String serverName = launchConfig.getAttribute(Server.NAME, ""); // $NON-NLS-1$
      if (!serverName.equals("")) { // $NON-NLS-1$
        Server server = ServersManager.getServer(serverName);
        if (server == null) {
          deleteLaunchConfiguration(launchConfig);
          ILaunchConfiguration[] allConfigurations =
              DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations();
          for (ILaunchConfiguration element : allConfigurations) {
            launchConfig = element;
            serverName = launchConfig.getAttribute(Server.NAME, ""); // $NON-NLS-1$
            if (!serverName.equals("")
                && ServersManager.getServer(serverName) == null) { // $NON-NLS-1$
              // The server was removed, so remove this launch
              // configuration!
              deleteLaunchConfiguration(launchConfig);
            }
          }
          return false;
        }
      }

      String fileName = launchConfig.getAttribute(Server.FILE_NAME, ""); // $NON-NLS-1$
      IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(fileName);
      if (!(resource instanceof IFile)) {
        setErrorMessage(
            PHPServerUIMessages.getString("ServerTab.file_project_doesNotExist")); // $NON-NLS-1$
        return false;
      }

    } catch (CoreException e) {
      // ignore
    }

    return isValidExtension(launchConfig);
  }
 /*
  * Select the default server.
  */
 private void selectDefaultServer(ILaunchConfiguration configuration) throws CoreException {
   if (serverCombo != null && serverCombo.getItemCount() > 0) {
     // Select the default server
     String projectName =
         configuration.getAttribute(IPHPDebugConstants.PHP_Project, (String) null);
     IProject project = null;
     if (projectName != null) {
       project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
     }
     Server defaultServer = ServersManager.getDefaultServer(project);
     int nameIndex = serverCombo.indexOf(defaultServer.getName());
     if (nameIndex > -1) {
       serverCombo.select(nameIndex);
     } else {
       serverCombo.select(0);
     }
     server = ServersManager.getServer(serverCombo.getText());
   }
 }