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

The following examples show how to use org.eclipse.core.runtime.IStatus#getMessage() . 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: SGenJavaValidator.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Check
public void checkFeatureConfiguration(FeatureConfiguration configuration) {
	GeneratorModel model = (GeneratorModel) EcoreUtil2.getRootContainer(configuration);

	Optional<IGeneratorDescriptor> generatorDescriptor = GeneratorExtensions
			.getGeneratorDescriptor(model.getGeneratorId());
	if (!generatorDescriptor.isPresent()) {
		return;
	}
	IDefaultFeatureValueProvider provider = LibraryExtensions.getDefaultFeatureValueProvider(
			generatorDescriptor.get().getLibraryIDs(), configuration.getType().getLibrary());
	injector.injectMembers(provider);
	IStatus status = provider.validateConfiguration(configuration);
	if (status.getSeverity() == IStatus.ERROR) {
		super.error(status.getMessage(), SGenPackage.Literals.FEATURE_CONFIGURATION__TYPE);
	}
}
 
Example 2
Source File: MainProjectWizardPage.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Check the project name.
 *
 * @param workspace the workspace.
 * @param name name of the project.
 * @throws ValidationException if the name is invalid.
 */
private void checkProjectName(IWorkspace workspace, String name)  throws ValidationException {
	// check whether the project name field is empty
	if (name.length() == 0) {
		throw new ValidationException(
				NewWizardMessages.NewJavaProjectWizardPageOne_Message_enterProjectName,
				null);
	}

	// check whether the project name is valid
	final IStatus nameStatus = workspace.validateName(name, IResource.PROJECT);
	if (!nameStatus.isOK()) {
		throw new ValidationException(
				null,
				nameStatus.getMessage());
	}
}
 
Example 3
Source File: OrganizationNameCellEditorValidator.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String isValid(final Object input) {
    //Check Emptiness
    if (input == null || input.toString().isEmpty()) {
		return Messages.nameIsEmpty ;
	}

    final String toValidate = input.toString();
    //Check valid File name
    final FileNameValidator fileNameValidator = new FileNameValidator(Messages.organizationName);
    final IStatus fileNameValidationStatus = fileNameValidator.validate(toValidate);
    if (!fileNameValidationStatus.isOK()) {
        return fileNameValidationStatus.getMessage();
    }
    //Check unicity
    final OrganizationRepositoryStore store = getOrganizationStore();
    if (store.getChild(toValidate + "." + OrganizationRepositoryStore.ORGANIZATION_EXT, true) != null) {
		return Messages.nameAlreadyExists ;
	}
	return null;
}
 
Example 4
Source File: CloudSdkManager.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * Installs a Cloud SDK, if the preferences are configured to auto-manage the SDK. Blocks callers
 * 1) if the managed SDK is being installed concurrently by others; and 2) until the installation
 * is complete.
 *
 * @param consoleStream stream to which the install output is written
 * @param monitor the progress monitor that can also be used to cancel the installation
 */
public IStatus installManagedSdk(MessageConsoleStream consoleStream, IProgressMonitor monitor) {
  if (CloudSdkPreferences.isAutoManaging()) {
    // We don't check if the Cloud SDK installed but always schedule the install job; such check
    // may pass while the SDK is being installed and in an incomplete state.
    // Mark installation failure as non-ERROR to avoid job failure reporting dialogs from the
    // overly helpful Eclipse UI ProgressManager
    CloudSdkInstallJob installJob = new CloudSdkInstallJob(
        consoleStream, modifyLock, IStatus.WARNING);

    IStatus result = runInstallJob(consoleStream, installJob, monitor);
    if (!result.isOK()) {
      // recast result as an IStatus.ERROR
      return new Status(
          IStatus.ERROR,
          result.getPlugin(),
          result.getCode(),
          result.getMessage(),
          result.getException());
    }
  }
  return Status.OK_STATUS;
}
 
Example 5
Source File: StatusUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Applies the status to the status line of a dialog page.
 * @param page the dialog page
 * @param status the status to apply
 */
public static void applyToStatusLine(DialogPage page, IStatus status) {
	String message= status.getMessage();
	if (message != null && message.length() == 0) {
		message= null;
	}
	switch (status.getSeverity()) {
		case IStatus.OK:
			page.setMessage(message, IMessageProvider.NONE);
			page.setErrorMessage(null);
			break;
		case IStatus.WARNING:
			page.setMessage(message, IMessageProvider.WARNING);
			page.setErrorMessage(null);
			break;
		case IStatus.INFO:
			page.setMessage(message, IMessageProvider.INFORMATION);
			page.setErrorMessage(null);
			break;
		default:
			page.setMessage(null);
			page.setErrorMessage(message);
			break;
	}
}
 
Example 6
Source File: SelectLanguageConfigurationWizardPage.java    From tm4e with Eclipse Public License 1.0 6 votes vote down vote up
private static void applyToStatusLine(DialogPage page, IStatus status) {
	String message = Status.OK_STATUS.equals(status) ? null : status.getMessage();
	switch (status.getSeverity()) {
	case IStatus.OK:
		page.setMessage(message, IMessageProvider.NONE);
		page.setErrorMessage(null);
		break;
	case IStatus.WARNING:
		page.setMessage(message, IMessageProvider.WARNING);
		page.setErrorMessage(null);
		break;
	case IStatus.INFO:
		page.setMessage(message, IMessageProvider.INFORMATION);
		page.setErrorMessage(null);
		break;
	default:
		if (message != null && message.length() == 0) {
			message = null;
		}
		page.setMessage(null);
		page.setErrorMessage(message);
		break;
	}
}
 
Example 7
Source File: StatusUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Applies the status to the status line of a dialog page.
 * 
 * @param page
 *            the dialog page
 * @param status
 *            the status to apply
 */
public static void applyToStatusLine( DialogPage page, IStatus status )
{
	if ( status == null )
	{
		page.setMessage( null, IMessageProvider.NONE );
		page.setErrorMessage( null );
		return;
	}

	String message = status.getMessage( );

	if ( message != null && message.length( ) == 0 )
	{
		message = null;
	}

	switch ( status.getSeverity( ) )
	{
		case IStatus.OK :
			page.setMessage( message, IMessageProvider.NONE );
			page.setErrorMessage( null );
			break;
		case IStatus.WARNING :
			page.setMessage( message, IMessageProvider.WARNING );
			page.setErrorMessage( null );
			break;
		case IStatus.INFO :
			page.setMessage( message, IMessageProvider.INFORMATION );
			page.setErrorMessage( null );
			break;
		default :
			page.setMessage( null );
			page.setErrorMessage( message );
			break;
	}
}
 
Example 8
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 9
Source File: NodePackageManager.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public String getInstalledVersion(String packageName, boolean global, IPath workingDir) throws CoreException
{
	IPath npmPath = checkedNPMPath();
	List<String> args = CollectionsUtil.newList(npmPath.toOSString(), "ls", packageName, COLOR, FALSE); //$NON-NLS-1$
	if (global)
	{
		args.add(GLOBAL_ARG);
	}
	IStatus status = nodeJS.runInBackground(workingDir, ShellExecutable.getEnvironment(), args);
	if (!status.isOK())
	{
		throw new CoreException(new Status(IStatus.ERROR, JSCorePlugin.PLUGIN_ID, MessageFormat.format(
				Messages.NodePackageManager_FailedToDetermineInstalledVersion, packageName, status.getMessage())));
	}
	String output = status.getMessage();
	int index = output.indexOf(packageName + '@');
	if (index != -1)
	{
		output = output.substring(index + packageName.length() + 1);
		int space = output.indexOf(' ');
		if (space != -1)
		{
			output = output.substring(0, space);
		}
		return output;
	}
	return null;
}
 
Example 10
Source File: CommandScriptRunner.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * executeScript
 * 
 * @return
 */
public String executeScript()
{
	IPath shell;
	try
	{
		shell = ShellExecutable.getPath();
	}
	catch (CoreException e)
	{
		IdeLog.logError(ScriptingActivator.getDefault(), Messages.CommandScriptRunner_CANNOT_LOCATE_SHELL, e);
		this._exitValue = 1;
		this.setExecutedSuccessfully(false);
		return MessageFormat.format(Messages.CommandScriptRunner_UNABLE_TO_LOCATE_SHELL_FOR_COMMAND,
				new Object[] { this.getCommand().getPath() });
	}
	String[] commandLine = this.getCommandLineArguments();
	String resultText = null;
	String input = IOUtil.read(this.getContext().getInputStream(), IOUtil.UTF_8);
	List<String> args = new ArrayList<String>(Arrays.asList(commandLine));
	args.add(0, shell.toOSString());
	IStatus result = new ProcessRunner().runInBackground(this.getCommand().getWorkingDirectory(),
			this.getContributedEnvironment(), input, args);

	if (result == null)
	{
		this._exitValue = 1;
		this.setExecutedSuccessfully(false);
	}
	else
	{
		this._exitValue = result.getCode();
		resultText = result.getMessage();
		this.setExecutedSuccessfully(this._exitValue == 0);
	}
	return resultText;
}
 
Example 11
Source File: ImportHandler.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private static void initializeTraceResource(final LttngRelaydConnectionInfo connectionInfo, final String tracePath, final IProject project) throws CoreException, TmfTraceImportException {
    final TmfProjectElement projectElement = TmfProjectRegistry.getProject(project, true);
    final TmfTraceFolder tracesFolder = projectElement.getTracesFolder();
    if (tracesFolder != null) {
        IFolder folder = tracesFolder.getResource();
        IFolder traceFolder = folder.getFolder(connectionInfo.getSessionName());
        Path location = new Path(tracePath);
        IStatus result = ResourcesPlugin.getWorkspace().validateLinkLocation(folder, location);
        if (result.isOK()) {
            traceFolder.createLink(location, IResource.REPLACE, new NullProgressMonitor());
        } else {
            throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, result.getMessage()));
        }

        TraceTypeHelper selectedTraceType = TmfTraceTypeUIUtils.selectTraceType(location.toOSString(), null, null);
        // No trace type was determined.
        TmfTraceTypeUIUtils.setTraceType(traceFolder, selectedTraceType);

        TmfTraceElement found = null;
        final List<TmfTraceElement> traces = tracesFolder.getTraces();
        for (TmfTraceElement candidate : traces) {
            if (candidate.getName().equals(connectionInfo.getSessionName())) {
                found = candidate;
            }
        }

        if (found == null) {
            throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_LiveTraceElementError));
        }

        // Properties used to be able to reopen a trace in live mode
        traceFolder.setPersistentProperty(CtfConstants.LIVE_HOST, connectionInfo.getHost());
        traceFolder.setPersistentProperty(CtfConstants.LIVE_PORT, Integer.toString(connectionInfo.getPort()));
        traceFolder.setPersistentProperty(CtfConstants.LIVE_SESSION_NAME, connectionInfo.getSessionName());

        final TmfTraceElement finalTrace = found;
        Display.getDefault().syncExec(() -> TmfOpenTraceHelper.openFromElement(finalTrace));
    }
}
 
Example 12
Source File: JSDiagnosticLog.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private String getInstalledNpmPackages(INodePackageManager npm) throws CoreException
{
	IStatus status = npm.runInBackground(INodePackageManager.GLOBAL_ARG, "list", "--depth=0"); //$NON-NLS-1$ //$NON-NLS-2$
	String listOutput = status.getMessage();

	// Hack : An issue in npm list command show errors or warnings because of depth option. Filter them out of the
	// output.
	int errIndex = listOutput.indexOf("npm ERR!"); //$NON-NLS-1$
	if (errIndex != -1)
	{
		listOutput = listOutput.substring(0, errIndex);
	}
	return listOutput;
}
 
Example 13
Source File: WizardReportSettingPage.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Applies the status to the status line of a dialog page.
 */
private void applyToStatusLine( IStatus status )
{
	String message = status.getMessage( );
	if ( message.length( ) == 0 )
		message = pageDesc;
	switch ( status.getSeverity( ) )
	{
		case IStatus.OK :
			setErrorMessage( null );
			setMessage( message );
			break;
		case IStatus.ERROR :
			setErrorMessage( message );
			setMessage( message, WizardPage.ERROR );
			break;
		case IStatus.WARNING :
			setErrorMessage( null );
			setMessage( message, WizardPage.WARNING );
			break;
		case IStatus.INFO :
			setErrorMessage( null );
			setMessage( message, WizardPage.INFORMATION );
			break;
		default :
			setErrorMessage( message );
			setMessage( null );
			break;
	}
}
 
Example 14
Source File: SGenJavaValidator.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
private void createMarker(IStatus status) {
	switch (status.getSeverity()) {
	case IStatus.ERROR: {
		if (status instanceof ErrorCodeStatus) {
			super.error(status.getMessage(), SGenPackage.Literals.FEATURE_PARAMETER_VALUE__EXPRESSION,
					((ErrorCodeStatus) status).getErrorCode());
		}else {
			super.error(status.getMessage(), SGenPackage.Literals.FEATURE_PARAMETER_VALUE__EXPRESSION);
		}
		break;
	}
	case IStatus.WARNING:
		super.warning(status.getMessage(), SGenPackage.Literals.FEATURE_PARAMETER_VALUE__EXPRESSION);
	}
}
 
Example 15
Source File: GdbVariableVMNode_Override.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Object getPropertyValue(String propertyName, IStatus status,
		Map<String, Object> properties) {
       if (PROP_ERROR_MESSAGE.equals(propertyName)) {
           String message = status.getMessage();
		if (status.getChildren().length < 2) {
			if(message.contains("Error message from debugger back end:")) {
				for (String messageToTrim : MESSAGES_TO_TRIM) {
					if(message.contains(messageToTrim)) {
						message = StringUtil.substringFromMatch(messageToTrim, message);
						break;
					}
				}
			}
			
               return replaceNewlines(message);
           } else {
               StringBuffer buf = new StringBuffer(message);
               for  (IStatus childStatus : status.getChildren()) {
                   buf.append(MessagesForDebugVM.ErrorLabelText_Error_message__text_page_break_delimiter);
                   buf.append( replaceNewlines(childStatus.getMessage()) );
               }
               return buf.toString();
           }
       }
	return super.getPropertyValue(propertyName, status, properties);
}
 
Example 16
Source File: EnterProjectNamePage.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Checks if the project options for the given project id are valid.
 *
 * @return an error message if the options are not valid, otherwise the error message is <code>
 *     null</code>
 */
private String isProjectSelectionValid(String projectID) {

  ProjectOptionComposite projectOptionComposite = projectOptionComposites.get(projectID);

  String projectName = projectOptionComposite.getProjectName();

  if (projectName.isEmpty())
    return Messages.EnterProjectNamePage_set_project_name
        + " for remote project "
        + remoteProjectIdToNameMapping.get(projectID);

  IStatus status = ResourcesPlugin.getWorkspace().validateName(projectName, IResource.PROJECT);

  if (!status.isOK())
    // FIXME display remote project name
    return status.getMessage();

  List<String> currentProjectNames = getCurrentProjectNames(projectID);

  if (currentProjectNames.contains(projectName))
    // FIXME display the project ... do not let the user guess
    return MessageFormat.format(
        Messages.EnterProjectNamePage_error_projectname_in_use, projectName);

  IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);

  if (projectOptionComposite.useExistingProject() && !project.exists())
    // FIXME crap error message
    return Messages.EnterProjectNamePage_error_wrong_name
        + " "
        + projectOptionComposite.getProjectName();

  if (!projectOptionComposite.useExistingProject() && project.exists())
    // FIXME we are working with tabs ! always display the remote
    // project name
    return MessageFormat.format(
        Messages.EnterProjectNamePage_error_projectname_exists, projectName);

  return null;
}
 
Example 17
Source File: InputValidatorWrapper.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String isValid(String newText) {
    final IStatus status = validator.validate(newText);
    return status.isOK() ? null : status.getMessage();
}
 
Example 18
Source File: SVNAction.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Method that implements generic handling of an exception. 
 * 
 * Thsi method will also use any accumulated status when determining what
 * information (if any) to show the user.
 * 
 * @param exception the exception that occured (or null if none occured)
 * @param status any status accumulated by the action before the end of 
 * the action or the exception occured.
 */
protected void handle(Exception exception) {
	if (exception instanceof SVNException) {
		if (((SVNException)exception).operationInterrupted()) {
			return;
		}
	}
	// Get the non-OK statii
	List problems = new ArrayList();
	IStatus[] status = getAccumulatedStatus();
	if (status != null) {
		for (int i = 0; i < status.length; i++) {
			IStatus iStatus = status[i];
			if ( ! iStatus.isOK() || iStatus.getCode() == SVNStatus.SERVER_ERROR) {
				problems.add(iStatus);
			}
		}
	}
	// Handle the case where there are no problem statii
	if (problems.size() == 0) {
		if (exception == null) return;
		handle(exception, getErrorTitle(), null);
		return;
	}

	// For now, display both the exception and the problem status
	// Later, we can determine how to display both together
	if (exception != null) {
		handle(exception, getErrorTitle(), null);
	}
	
	String message = null;
	IStatus statusToDisplay = getStatusToDisplay((IStatus[]) problems.toArray(new IStatus[problems.size()]));
	if (statusToDisplay.isOK()) return;
	if (statusToDisplay.isMultiStatus() && statusToDisplay.getChildren().length == 1) {
		message = statusToDisplay.getMessage();
		statusToDisplay = statusToDisplay.getChildren()[0];
	}
	String title;
	if (statusToDisplay.getSeverity() == IStatus.ERROR) {
		title = getErrorTitle();
	} else {
		title = getWarningTitle();
	}
	SVNUIPlugin.openError(getShell(), title, message, new SVNException(statusToDisplay));
}
 
Example 19
Source File: WorkspaceFile.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private static void fileNotFoundError(CoreException cause, IPath path) throws CoreException {
	IStatus status = cause.getStatus();
	throw new CoreException(new Status(status.getSeverity(), status.getPlugin(), status.getCode(), status.getMessage(), new FileNotFoundException(path.toPortableString())));
}
 
Example 20
Source File: ExchangeException.java    From elexis-3-core with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Creates a new exception with the given status object. The message of the given status is used
 * as the exception message.
 * 
 * @param status
 *            the status object to be associated with this exception
 */
public ExchangeException(IStatus status){
	super(status.getMessage());
	this.status = status;
}