Java Code Examples for org.eclipse.ui.internal.ide.IDEWorkbenchPlugin#getPluginWorkspace()

The following examples show how to use org.eclipse.ui.internal.ide.IDEWorkbenchPlugin#getPluginWorkspace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RenameResourceAction.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Return the new name to be given to the target resource.
 *
 * @return java.lang.String
 * @param resource
 *            the resource to query status on
 */
protected String queryNewResourceName(final IResource resource) {
	final IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();
	final IPath prefix = resource.getFullPath().removeLastSegments(1);
	final IInputValidator validator = string -> {
		if (resource.getName().equals(string)) {
			return IDEWorkbenchMessages.RenameResourceAction_nameMustBeDifferent;
		}
		final IStatus status = workspace.validateName(string, resource.getType());
		if (!status.isOK()) { return status.getMessage(); }
		if (workspace.getRoot().exists(prefix.append(string))) {
			return IDEWorkbenchMessages.RenameResourceAction_nameExists;
		}
		return null;
	};

	final InputDialog dialog =
			new InputDialog(WorkbenchHelper.getShell(), IDEWorkbenchMessages.RenameResourceAction_inputDialogTitle,
					IDEWorkbenchMessages.RenameResourceAction_inputDialogMessage, resource.getName(), validator);
	dialog.setBlockOnOpen(true);
	final int result = dialog.open();
	if (result == Window.OK) { return dialog.getValue(); }
	return null;
}
 
Example 2
Source File: NewUZProjectWizardPage.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
protected boolean validatePage() {
  	canFinish=false;	
  	   getShell().setText(Messages.CREATEPROJECTWIZARD);
      IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();

      String projectFieldContents = getProjectNameFieldValue();
      if (projectFieldContents.equals("")) {
          setErrorMessage(null);
          setMessage(IDEWorkbenchMessages.WizardNewProjectCreationPage_projectNameEmpty);
          return false;
      }

      IStatus nameStatus = workspace.validateName(projectFieldContents,
              IResource.PROJECT);
      if (!nameStatus.isOK()) {
          setErrorMessage(nameStatus.getMessage());
          return false;
      }
     
      IProject handle = getProjectHandle();
      if (handle.exists()) {
          setErrorMessage(IDEWorkbenchMessages.WizardNewProjectCreationPage_projectExistsMessage);
          return false;
      }
return dialogChanged();
  }
 
Example 3
Source File: ExtensibleWizardNewProjectCreationPage.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns whether this page's controls currently all contain valid values.
 *
 * @return <code>true</code> if all controls are valid, and <code>false</code> if at least one is invalid
 */
protected boolean validatePage() {
	IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();

	// CHANGED: use getProjectName to allow subclasses to control what concrete project name value is validated
	String projectFieldContents = getProjectName();
	if (projectFieldContents.equals("")) { //$NON-NLS-1$
		setErrorMessage(null);
		setMessage(IDEWorkbenchMessages.WizardNewProjectCreationPage_projectNameEmpty);
		return false;
	}

	IStatus nameStatus = workspace.validateName(projectFieldContents,
			IResource.PROJECT);
	if (!nameStatus.isOK()) {
		setErrorMessage(nameStatus.getMessage());
		return false;
	}

	IProject handle = getProjectHandle();
	if (handle.exists()) {
		setErrorMessage(IDEWorkbenchMessages.WizardNewProjectCreationPage_projectExistsMessage);
		return false;
	}

	// CHANGED: allow getProjectHandle to control the IProject instance used here
	locationArea.setExistingProject(handle);

	String validLocationMessage = locationArea.checkValidLocation();
	if (validLocationMessage != null) { // there is no destination location given
		setErrorMessage(validLocationMessage);
		return false;
	}

	setErrorMessage(null);
	setMessage(null);
	return true;
}
 
Example 4
Source File: NewProjectWizardPage.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns whether this page's controls currently all contain valid values.
 *
 * @return <code>true</code> if all controls are valid, and <code>false</code> if at least one is invalid
 */
protected boolean validatePage() {
	final IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();

	final String projectFieldContents = getProjectNameFieldValue();
	if (projectFieldContents.equals("")) { //$NON-NLS-1$
		setErrorMessage(null);
		setMessage(IDEWorkbenchMessages.WizardNewProjectCreationPage_projectNameEmpty);
		return false;
	}

	final IStatus nameStatus = workspace.validateName(projectFieldContents, IResource.PROJECT);
	if (!nameStatus.isOK()) {
		setErrorMessage(nameStatus.getMessage());
		return false;
	}

	final IProject handle = getProjectHandle();
	if (handle.exists()) {
		getProjectHandle();
		setErrorMessage(IDEWorkbenchMessages.WizardNewProjectCreationPage_projectExistsMessage);
		return false;
	}

	// final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(getProjectNameFieldValue());
	// locationArea.setExistingProject(project);

	// final String validLocationMessage = locationArea.checkValidLocation();
	// if (validLocationMessage != null) { // there is no destination location given
	// setErrorMessage(validLocationMessage);
	// return false;
	// }

	setErrorMessage(null);
	setMessage(null);
	return true;
}
 
Example 5
Source File: WizardNewProjectCreationPage.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
   * Returns whether this page's controls currently all contain valid 
   * values.
   *
   * @return <code>true</code> if all controls are valid, and
   *   <code>false</code> if at least one is invalid
   */
  protected boolean validatePage() {
      IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();

      String projectFieldContents = getProjectNameFieldValue();
      if (projectFieldContents.equals("")) { //$NON-NLS-1$
          setErrorMessage(null);
          setMessage(IDEWorkbenchMessages.WizardNewProjectCreationPage_projectNameEmpty);
          return false;
      }

      IStatus nameStatus = workspace.validateName(projectFieldContents,
              IResource.PROJECT);
      if (!nameStatus.isOK()) {
          setErrorMessage(nameStatus.getMessage());
          return false;
      }

      IProject handle = getProjectHandle();
      if (handle.exists()) {
          setErrorMessage(IDEWorkbenchMessages.WizardNewProjectCreationPage_projectExistsMessage);
          return false;
      }
              
      IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(
		getProjectNameFieldValue());
locationArea.setExistingProject(project);

String validLocationMessage = locationArea.checkValidLocation();
if (validLocationMessage != null) { // there is no destination location given
	setErrorMessage(validLocationMessage);
	return false;
}

      setErrorMessage(null);
      setMessage(null);
      return true;
  }
 
Example 6
Source File: RenameResourceAndCloseEditorAction.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the new name to be given to the target resource.
 * 
 * @return java.lang.String
 * @param resource
 *            the resource to query status on
 */
protected String queryNewResourceName(final IResource resource) {
	final IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();
	final IPath prefix = resource.getFullPath().removeLastSegments(1);
	IInputValidator validator = new IInputValidator() {
		public String isValid(String string) {
			if (resource.getName().equals(string)) {
				return IDEWorkbenchMessages.RenameResourceAction_nameMustBeDifferent;
			}
			IStatus status = workspace.validateName(string, resource
					.getType());
			if (!status.isOK()) {
				return status.getMessage();
			}
			if (workspace.getRoot().exists(prefix.append(string))) {
				return IDEWorkbenchMessages.RenameResourceAction_nameExists;
			}
			return null;
		}
	};

	InputDialog dialog = new InputDialog(shellProvider.getShell(),
			IDEWorkbenchMessages.RenameResourceAction_inputDialogTitle,
			IDEWorkbenchMessages.RenameResourceAction_inputDialogMessage,
			resource.getName(), validator);
	dialog.setBlockOnOpen(true);
	int result = dialog.open();
	if (result == Window.OK)
		return dialog.getValue();
	return null;
}
 
Example 7
Source File: RenameResourceAndCloseEditorAction.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the new name to be given to the target resource.
 * 
 * @return java.lang.String
 * @param resource
 *            the resource to query status on
 */
protected String queryNewResourceName(final IResource resource) {
	final IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();
	final IPath prefix = resource.getFullPath().removeLastSegments(1);
	IInputValidator validator = new IInputValidator() {
		public String isValid(String string) {
			if (resource.getName().equals(string)) {
				return IDEWorkbenchMessages.RenameResourceAction_nameMustBeDifferent;
			}
			IStatus status = workspace.validateName(string, resource
					.getType());
			if (!status.isOK()) {
				return status.getMessage();
			}
			if (workspace.getRoot().exists(prefix.append(string))) {
				return IDEWorkbenchMessages.RenameResourceAction_nameExists;
			}
			return null;
		}
	};

	InputDialog dialog = new InputDialog(shellProvider.getShell(),
			IDEWorkbenchMessages.RenameResourceAction_inputDialogTitle,
			IDEWorkbenchMessages.RenameResourceAction_inputDialogMessage,
			resource.getName(), validator);
	dialog.setBlockOnOpen(true);
	int result = dialog.open();
	if (result == Window.OK)
		return dialog.getValue();
	return null;
}
 
Example 8
Source File: PyRenameResourceAction.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Return the new name to be given to the target resource.
 *
 * @return java.lang.String
 * @param resource the resource to query status on
 *
 * Fix from platform: was not checking return from dialog.open
 */
@Override
protected String queryNewResourceName(final IResource resource) {
    final IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();
    final IPath prefix = resource.getFullPath().removeLastSegments(1);
    IInputValidator validator = new IInputValidator() {
        @Override
        public String isValid(String string) {
            if (resource.getName().equals(string)) {
                return IDEWorkbenchMessages.RenameResourceAction_nameMustBeDifferent;
            }
            IStatus status = workspace.validateName(string, resource.getType());
            if (!status.isOK()) {
                return status.getMessage();
            }
            if (workspace.getRoot().exists(prefix.append(string))) {
                return IDEWorkbenchMessages.RenameResourceAction_nameExists;
            }
            return null;
        }
    };

    InputDialog dialog = new InputDialog(shell, IDEWorkbenchMessages.RenameResourceAction_inputDialogTitle,
            IDEWorkbenchMessages.RenameResourceAction_inputDialogMessage, resource.getName(), validator);
    dialog.setBlockOnOpen(true);
    if (dialog.open() == Window.OK) {
        return dialog.getValue();
    } else {
        return null;
    }
}
 
Example 9
Source File: RenameResourceAndCloseEditorAction.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Save the changes and dispose of the text widget.
 * 
 * @param resource -
 *            the resource to move.
 */
private void saveChangesAndDispose(IResource resource) {
	if (saving == true) {
		return;
	}

	saving = true;
	// Cache the resource to avoid selection loss since a selection of
	// another item can trigger this method
	inlinedResource = resource;
	final String newName = textEditor.getText();
	
	
	// Run this in an async to make sure that the operation that triggered
	// this action is completed. Otherwise this leads to problems when the
	// icon of the item being renamed is clicked (i.e., which causes the
	// rename
	// text widget to lose focus and trigger this method).
	Runnable query = new Runnable() {
		public void run() {
			try {
				if (!newName.equals(inlinedResource.getName())) {
					IWorkspace workspace = IDEWorkbenchPlugin
							.getPluginWorkspace();
					IStatus status = workspace.validateName(newName,
							inlinedResource.getType());
					if (!status.isOK()) {
						displayError(status.getMessage());
					} else {
						// 验证资源名称是否合法	robert	2013-07-01
						String validResult = CommonFunction.validResourceName(newName);
						if (validResult != null) {
							displayError(validResult);
						}else {
							IPath newPath = inlinedResource.getFullPath()
									.removeLastSegments(1).append(newName);
							runWithNewPath(newPath, inlinedResource);
						}
					}
				}
				inlinedResource = null;
				// Dispose the text widget regardless
				disposeTextWidget();
				// Ensure the Navigator tree has focus, which it may not if
				// the
				// text widget previously had focus.
				if (navigatorTree != null && !navigatorTree.isDisposed()) {
					navigatorTree.setFocus();
				}
			} finally {
				saving = false;
			}
		}
	};
	getTree().getShell().getDisplay().asyncExec(query);
}
 
Example 10
Source File: RenameResourceAndCloseEditorAction.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Save the changes and dispose of the text widget.
 * 
 * @param resource -
 *            the resource to move.
 */
private void saveChangesAndDispose(IResource resource) {
	if (saving == true) {
		return;
	}

	saving = true;
	// Cache the resource to avoid selection loss since a selection of
	// another item can trigger this method
	inlinedResource = resource;
	final String newName = textEditor.getText();
	// Run this in an async to make sure that the operation that triggered
	// this action is completed. Otherwise this leads to problems when the
	// icon of the item being renamed is clicked (i.e., which causes the
	// rename
	// text widget to lose focus and trigger this method).
	Runnable query = new Runnable() {
		public void run() {
			try {
				if (!newName.equals(inlinedResource.getName())) {
					IWorkspace workspace = IDEWorkbenchPlugin
							.getPluginWorkspace();
					IStatus status = workspace.validateName(newName,
							inlinedResource.getType());
					if (!status.isOK()) {
						displayError(status.getMessage());
					} else {
						IPath newPath = inlinedResource.getFullPath()
								.removeLastSegments(1).append(newName);
						runWithNewPath(newPath, inlinedResource);
					}
				}
				inlinedResource = null;
				// Dispose the text widget regardless
				disposeTextWidget();
				// Ensure the Navigator tree has focus, which it may not if
				// the
				// text widget previously had focus.
				if (navigatorTree != null && !navigatorTree.isDisposed()) {
					navigatorTree.setFocus();
				}
			} finally {
				saving = false;
			}
		}
	};
	getTree().getShell().getDisplay().asyncExec(query);
}
 
Example 11
Source File: NewFolderDialogOfHs.java    From translationstudio8 with GNU General Public License v2.0 votes vote down vote up
/**
		 * Returns whether the container specified in the constructor is
		 * a valid parent for creating linked resources.
		 * 
		 * @return boolean <code>true</code> if the container specified in 
		 * 	the constructor is a valid parent for creating linked resources.
		 * 	<code>false</code> if no linked resources may be created with the
		 * 	specified container as a parent. 
		 */
		private boolean isValidContainer() {
			if (container.getType() != IResource.PROJECT
					&& container.getType() != IResource.FOLDER) {
				return false;
			}

			try {
				IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();
				IProject project = container.getProject();
				String[] natureIds = project.getDescription().getNatureIds();

				for (int i = 0; i < natureIds.length; i++) {
					IProjectNatureDescriptor descriptor = workspace
							.getNatureDescriptor(natureIds[i]);
					if (descriptor != null
							&& descriptor.isLinkingAllowed() == false) {
						return false;
					}
				}
			} catch (CoreException exception) {
				// project does not exist or is closed
				return false;
			}
			return true;
		}