Java Code Examples for org.eclipse.core.runtime.IStatus#matches()

The following examples show how to use org.eclipse.core.runtime.IStatus#matches() . 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: NewTxtUMLProjectWizardPage.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected boolean validatePage() {
	if (!super.validatePage())
		return false;
	IStatus status = JavaConventions.validatePackageName(getProjectName(), JavaCore.VERSION_1_5,
			JavaCore.VERSION_1_5);
	if (!status.isOK()) {
		if (status.matches(IStatus.WARNING)) {
			setMessage(status.getMessage(), IStatus.WARNING);
			return true;
		}
		setErrorMessage(Messages.WizardNewtxtUMLProjectCreationPage_ErrorMessageProjectName + status.getMessage());
		return false;
	}
	setErrorMessage(null);
	setMessage(null);
	return true;
}
 
Example 2
Source File: CodeAssistFavoritesConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void doValidation() {
	StatusInfo status= new StatusInfo();
	String newText= fNameDialogField.getText();
	if (newText.length() == 0) {
		status.setError(""); //$NON-NLS-1$
	} else {
		IStatus val= JavaConventions.validateJavaTypeName(newText, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
		if (val.matches(IStatus.ERROR)) {
			if (fIsEditingMember)
				status.setError(PreferencesMessages.FavoriteStaticMemberInputDialog_error_invalidMemberName);
			else
				status.setError(PreferencesMessages.FavoriteStaticMemberInputDialog_error_invalidTypeName);
		} else {
			if (doesExist(newText)) {
				status.setError(PreferencesMessages.FavoriteStaticMemberInputDialog_error_entryExists);
			}
		}
	}
	updateStatus(status);
}
 
Example 3
Source File: ModifyDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void doValidate() {
  	String name= fProfileNameField.getText().trim();
if (name.equals(fProfile.getName()) && fProfile.hasEqualSettings(fWorkingValues, fWorkingValues.keySet())) {
	updateStatus(StatusInfo.OK_STATUS);
	return;
}

  	IStatus status= validateProfileName();
  	if (status.matches(IStatus.ERROR)) {
  		updateStatus(status);
  		return;
  	}

if (!name.equals(fProfile.getName()) && fProfileManager.containsName(name)) {
	updateStatus(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, FormatterMessages.ModifyDialog_Duplicate_Status));
	return;
}

if (fProfile.isBuiltInProfile() || fProfile.isSharedProfile()) {
	updateStatus(new Status(IStatus.INFO, JavaUI.ID_PLUGIN, FormatterMessages.ModifyDialog_NewCreated_Status));
	return;
}

   updateStatus(StatusInfo.OK_STATUS);
  }
 
Example 4
Source File: NameConventionConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IStatus validateIdentifiers(String[] values, boolean prefix) {
	for (int i= 0; i < values.length; i++) {
		String val= values[i];
		if (val.length() == 0) {
			if (prefix) {
				return new StatusInfo(IStatus.ERROR, PreferencesMessages.NameConventionConfigurationBlock_error_emptyprefix);
			} else {
				return new StatusInfo(IStatus.ERROR, PreferencesMessages.NameConventionConfigurationBlock_error_emptysuffix);
			}
		}
		String name= prefix ? val + "x" : "x" + val; //$NON-NLS-2$ //$NON-NLS-1$
		IStatus status= JavaConventions.validateIdentifier(name, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
		if (status.matches(IStatus.ERROR)) {
			if (prefix) {
				return new StatusInfo(IStatus.ERROR, Messages.format(PreferencesMessages.NameConventionConfigurationBlock_error_invalidprefix, val));
			} else {
				return new StatusInfo(IStatus.ERROR, Messages.format(PreferencesMessages.NameConventionConfigurationBlock_error_invalidsuffix, val));
			}
		}
	}
	return new StatusInfo();
}
 
Example 5
Source File: UserLibraryPreferencePage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IStatus validateSettings() {
	String name= fNameField.getText();
	if (name.length() == 0) {
		return new StatusInfo(IStatus.ERROR, PreferencesMessages.UserLibraryPreferencePage_LibraryNameDialog_name_error_entername);
	}
	for (int i= 0; i < fExistingLibraries.size(); i++) {
		CPUserLibraryElement curr= fExistingLibraries.get(i);
		if (curr != fElementToEdit && name.equals(curr.getName())) {
			return new StatusInfo(IStatus.ERROR, Messages.format(PreferencesMessages.UserLibraryPreferencePage_LibraryNameDialog_name_error_exists, name));
		}
	}
	IStatus status= ResourcesPlugin.getWorkspace().validateName(name, IResource.FILE);
	if (status.matches(IStatus.ERROR)) {
		return new StatusInfo(IStatus.ERROR, "Name contains invalid characters."); //$NON-NLS-1$
	}
	return StatusInfo.OK_STATUS;
}
 
Example 6
Source File: JavaBuildConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IStatus validateResourceFilters() {
	String text= getValue(PREF_RESOURCE_FILTER);

	IWorkspace workspace= ResourcesPlugin.getWorkspace();

	String[] filters= getTokens(text, ","); //$NON-NLS-1$
	for (int i= 0; i < filters.length; i++) {
		String fileName= filters[i].replace('*', 'x');
		int resourceType= IResource.FILE;
		int lastCharacter= fileName.length() - 1;
		if (lastCharacter >= 0 && fileName.charAt(lastCharacter) == '/') {
			fileName= fileName.substring(0, lastCharacter);
			resourceType= IResource.FOLDER;
		}
		IStatus status= workspace.validateName(fileName, resourceType);
		if (status.matches(IStatus.ERROR)) {
			String message= Messages.format(PreferencesMessages.JavaBuildConfigurationBlock_filter_invalidsegment_error, status.getMessage());
			return new StatusInfo(IStatus.ERROR, message);
		}
	}
	return new StatusInfo();
}
 
Example 7
Source File: ExpandWithConstructorsConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Validates the entered type or member and updates the status.
 */
private void doValidation() {
	StatusInfo status= new StatusInfo();
	String newText= fNameDialogField.getText();
	if (newText.length() == 0) {
		status.setError(""); //$NON-NLS-1$
	} else {
		IStatus val= JavaConventions.validateJavaTypeName(newText, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
		if (val.matches(IStatus.ERROR)) {
			if (fIsEditingMember)
				status.setError(CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_error_invalidMemberName);
			else
				status.setError(CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_error_invalidTypeName);
		} else {
			if (doesExist(newText)) {
				status.setError(CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_error_entryExists);
			}
		}
	}
	updateStatus(status);
}
 
Example 8
Source File: NewCheckCatalogWizardPage.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public IStatus typeNameChanged() {
  super.typeNameChanged();
  IStatus status = validator.checkCatalogName(getCatalogName());

  if (!previousPageIsProjectPage()) {

    IPackageFragment packageFragment = getPackageFragment();

    if (packageFragment != null && catalogExists(packageFragment.getResource())) {
      return new Status(IStatus.ERROR, status.getPlugin(), NLS.bind(com.avaloq.tools.ddk.check.validation.Messages.CheckJavaValidator_CATALOG_NAME_STATUS, com.avaloq.tools.ddk.check.validation.Messages.CheckJavaValidator_EXISTS));
    }
  }
  if (!status.matches(IStatus.ERROR)) {
    projectInfo.setCatalogName(getCatalogName());
  }
  return status;
}
 
Example 9
Source File: MultiElementListSelectionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see AbstractElementListSelectionDialog#updateButtonsEnableState(IStatus)
 */
@Override
protected void updateButtonsEnableState(IStatus status) {
	boolean isOK= !status.matches(IStatus.ERROR);
	fPages[fCurrentPage].okState= isOK;

	boolean isAllOK= isOK;
	for (int i= 0; i != fNumberOfPages; i++)
		isAllOK = isAllOK && fPages[i].okState;

	fFinishButton.setEnabled(isAllOK);

	boolean nextButtonEnabled= isOK && (fCurrentPage < fNumberOfPages - 1);

	fNextButton.setEnabled(nextButtonEnabled);
	fBackButton.setEnabled(fCurrentPage != 0);

	if (nextButtonEnabled) {
		getShell().setDefaultButton(fNextButton);
	} else if (isAllOK) {
		getShell().setDefaultButton(fFinishButton);
	}
}
 
Example 10
Source File: TexlipseWizardPage.java    From texlipse with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Add a status bar message.
 * 
 * @param page
 * @param status
 */
protected static void applyToStatusLine(DialogPage page, IStatus status) {

    String errorMessage = null;
    String warningMessage = null;
    String statusMessage = status.getMessage();
    
    if (statusMessage.length() > 0) {
        if (status.matches(IStatus.ERROR)) {
            errorMessage = statusMessage;
        } else if (!status.isOK()) {
            warningMessage = statusMessage;
        }
    }
    page.setErrorMessage(errorMessage);
    page.setMessage(warningMessage, status.getSeverity());
}
 
Example 11
Source File: FormatterModifyDialog.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * To use from tab validators, preserves error status for default profiles
 */
@Override 
protected void updateStatus(IStatus status) {
    if (isDefProfile && !status.matches(IStatus.ERROR)) {
            status = errDefStatus;
    }
    super.updateStatus(status);
}
 
Example 12
Source File: AbstractConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void numberFieldChanged(Text textControl) {
	String number= textControl.getText();
	IStatus status= validatePositiveNumber(number);
	if (!status.matches(IStatus.ERROR))
		fStore.setValue(fTextFields.get(textControl), number);
	updateStatus(status);
}
 
Example 13
Source File: AbstractWizardNewTypeScriptProjectCreationPage.java    From typescript.java with MIT License 5 votes vote down vote up
@Override
protected boolean validatePage() {
	boolean valid = super.validatePage();
	if (valid) {
		IStatus status = validatePageImpl();
		statusChanged(status);
		valid = !status.matches(IStatus.ERROR);
	}
	return valid;
}
 
Example 14
Source File: StatusUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public static IStatus getMostImportantStatusWithMessage(IStatus... status) {
  IStatus max = null;
  for (int i = 0; i < status.length; i++) {
    IStatus curr = status[i];
    if (curr.matches(IStatus.ERROR)) {
      return curr;
    }
    if (max == null || curr.getSeverity() > max.getSeverity()
        || max.getMessage().length() == 0) {
      max = curr;
    }
  }
  return max;
}
 
Example 15
Source File: AbstractProjectPropertyPage.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the IStatus with the most critical severity.
 */
protected static IStatus getMostImportantStatus(IStatus[] status) {
  IStatus max = null;
  for (int i = 0; i < status.length; i++) {
    IStatus curr = status[i];
    if (curr.matches(IStatus.ERROR)) {
      return curr;
    }
    if (max == null || curr.getSeverity() > max.getSeverity()
        || max.getMessage().length() == 0) {
      max = curr;
    }
  }
  return max;
}
 
Example 16
Source File: NewHostPageWizardPage.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private IStatus validatePath() {
  hostPagePath = null;

  pathField.enableButton(hostPageProject != null);

  String str = pathField.getText().trim();
  if (str.length() == 0) {
    return Util.newErrorStatus("Enter the file path");
  }

  if (hostPageProject == null) {
    // The rest of the path validation relies on having a valid project, so if
    // we don't have one, bail out here with an OK (the project's error will
    // supercede this one).
    return Status.OK_STATUS;
  }

  IPath path = new Path(hostPageProject.getName()).append(str).makeAbsolute();
  IStatus pathStatus = ResourcesPlugin.getWorkspace().validatePath(
      path.toString(), IResource.FOLDER);
  if (pathStatus.matches(IStatus.ERROR)) {
    return Util.newErrorStatus("Invalid path. {0}", pathStatus.getMessage());
  }

  // Path is valid
  hostPagePath = path;

  IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(path);
  if (!folder.exists()) {
    return Util.newWarningStatus(MessageFormat.format(
        "The path ''{0}'' does not exist.  It will be created when you click Finish.",
        path.toString()));
  }

  return Status.OK_STATUS;
}
 
Example 17
Source File: StatusUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Finds the most severe status from a array of stati.
 * An error is more severe than a warning, and a warning is more severe
 * than ok.
 * @param status an array of stati
 * @return the most severe status
 */
public static IStatus getMostSevere(IStatus[] status) {
	IStatus max= null;
	for (int i= 0; i < status.length; i++) {
		IStatus curr= status[i];
		if (curr.matches(IStatus.ERROR)) {
			return curr;
		}
		if (max == null || curr.getSeverity() > max.getSeverity()) {
			max= curr;
		}
	}
	return max;
}
 
Example 18
Source File: TexlipseWizardPage.java    From texlipse with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Update the status to the status bar.
 * 
 * The statusbar message is an error message, if at least one of the
 * fields has an invalid value. If the current field has an invalid value,
 * the corresponding error message is displayed. Otherwise,
 * the first error message found (starting from the top) is displayed.
 * 
 * @param lastStatus
 * @param number  
 */
protected void updateStatus(IStatus lastStatus, Object key) {
    
    IStatus status = null;
    boolean allOk = true;
    
    // update the status cache
    statusMap.put(key, lastStatus);
    
    // see if we got an error
    if (lastStatus.matches(IStatus.ERROR)) {
        status = lastStatus;
        allOk = false;
    } else {
    
        // see if some other value is invalid
        Iterator<IStatus> iter = statusMap.values().iterator();
        while (iter.hasNext()) {
            IStatus i = iter.next();
            if (!i.matches(IStatus.OK)) status = i;
            if (i.matches(IStatus.ERROR)) {
                allOk = false;
                break;
            }
        }
    }
    
    // enable/disable next-button
    setPageComplete(allOk);
    
    // only set status if this page is visible
    Control ctrl = getControl();
    if (ctrl != null && ctrl.isVisible()) {
        
        if (status == null) {
            status = lastStatus;
        }
        
        applyToStatusLine(this, status);
    }
}
 
Example 19
Source File: AddSourceFolderWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static StatusInfo validatePathName(String str, IContainer parent) {
	StatusInfo result= new StatusInfo();
	result.setOK();

	IPath parentPath= parent.getFullPath();

	if (str.length() == 0) {
		result.setError(Messages.format(NewWizardMessages.NewSourceFolderWizardPage_error_EnterRootName, BasicElementLabels.getPathLabel(parentPath, false)));
		return result;
	}

	IPath path= parentPath.append(str);

	IWorkspaceRoot workspaceRoot= ResourcesPlugin.getWorkspace().getRoot();
	IStatus validate= workspaceRoot.getWorkspace().validatePath(path.toString(), IResource.FOLDER);
	if (validate.matches(IStatus.ERROR)) {
		result.setError(Messages.format(NewWizardMessages.NewSourceFolderWizardPage_error_InvalidRootName, validate.getMessage()));
		return result;
	}

	IResource res= workspaceRoot.findMember(path);
	if (res != null) {
		if (res.getType() != IResource.FOLDER) {
			result.setError(NewWizardMessages.NewSourceFolderWizardPage_error_NotAFolder);
			return result;
		}
	} else {

		URI parentLocation= parent.getLocationURI();
		if (parentLocation != null) {
			try {
				IFileStore store= EFS.getStore(parentLocation).getChild(str);
				if (store.fetchInfo().exists()) {
					result.setError(NewWizardMessages.NewSourceFolderWizardPage_error_AlreadyExistingDifferentCase);
					return result;
				}
			} catch (CoreException e) {
				// we couldn't create the file store. Ignore the exception
				// since we can't check if the file exist. Pretend that it
				// doesn't.
			}
		}
	}

	return result;
}
 
Example 20
Source File: CheckJavaValidator.java    From dsl-devkit with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Creates an error or a warning depending on the severity of given status. Delegates to
 * {@link #warning(String, EObject, EStructuralFeature, String, String...)
 * warning} or {@link #error(String, EObject, EStructuralFeature, String, String...) error}.
 *
 * @param status
 *          a status with severity ERROR or WARNING
 * @param message
 *          the issue message
 * @param context
 *          the context object
 * @param feature
 *          the structural feature
 * @param code
 *          the issue code
 * @param issueData
 *          the issue data
 */
private void issue(final IStatus status, final String message, final EObject context, final EStructuralFeature feature, final String code, final String... issueData) {
  if (status.matches(IStatus.WARNING)) {
    warning(message, context, feature, code, issueData);
  } else if (status.matches(IStatus.ERROR)) {
    error(message, context, feature, code, issueData);
  }
}