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

The following examples show how to use org.eclipse.core.runtime.IStatus#isOK() . 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: ParametersWizardPage.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected String isNameValid(final String value) {
    final IStatus javaConventionNameStatus = new GroovyReferenceValidator(
            Messages.name).validate(value);
    if (!javaConventionNameStatus.isOK()) {
        return javaConventionNameStatus.getMessage();
    }
    final IStatus lenghtNameStatus = new InputLengthValidator(
            Messages.name, 50).validate(value);
    if (!lenghtNameStatus.isOK()) {
        return lenghtNameStatus.getMessage();
    }

    if (existingParameterNames.contains(value.toString())) {
        return Messages.invalidName;
    }

    return null;
}
 
Example 2
Source File: StatusUtil.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * Return a simplified status by discarding all OK child statuses.
 */
public static IStatus filter(IStatus status) {
  if (!status.isMultiStatus()) {
    return status;
  } else if (status.isOK()) {
    // return OK_STATUS to avoids oddities like Progress View showing the MultiStatus's
    // error message
    return Status.OK_STATUS;
  }
  MultiStatus newStatus = new MultiStatus(status.getPlugin(), status.getCode(),
      status.getMessage(), status.getException());
  for (IStatus child : status.getChildren()) {
    if (!child.isOK()) {
      newStatus.add(filter(child));
    }
  }
  return newStatus;
}
 
Example 3
Source File: FixCorrectionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Image getImage() {
	IStatus status= getFixStatus();
	if (status != null && !status.isOK()) {
		ImageImageDescriptor image= new ImageImageDescriptor(super.getImage());

		int flag= JavaElementImageDescriptor.WARNING;
		if (status.getSeverity() == IStatus.ERROR) {
			flag= JavaElementImageDescriptor.ERROR;
		}

		ImageDescriptor composite= new JavaElementImageDescriptor(image, flag, new Point(image.getImageData().width, image.getImageData().height));
		return composite.createImage();
	} else {
		return super.getImage();
	}
}
 
Example 4
Source File: ConverterViewModel.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 验证 xliff 所需要转换的 xliff 文件
 * @param xliffPath
 *            xliff 文件路径
 * @param monitor
 * @return ;
 */
public IStatus validateXliffFile(String xliffPath, XLFHandler handler, IProgressMonitor monitor) {
	IStatus result = new ReverseConversionValidateWithLibrary3().validate(xliffPath, configBean, monitor);
	if (!result.isOK()) {
		return result;
	}
	// 验证是否存在 xliff 对应的源文件类型的转换器实现
	String fileType = configBean.getFileType();
	Converter converter = getConverter(fileType);
	if (converter != null) {
		result = validateFileNodeInXliff(handler, xliffPath, converter.getType()); // 验证 XLIFF 文件的 file 节点
		if (!result.isOK()) {
			return result;
		}

		result = validIsSplitedXliff(handler, xliffPath);
		if (!result.isOK()) {
			return result;
		}
		setSelectedType(fileType);
		result = Status.OK_STATUS;
	} else {
		result = ValidationStatus.error(Messages.getString("model.ConverterViewModel.msg3") + fileType);
	}
	return result;
}
 
Example 5
Source File: ConverterViewModel.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 验证 xliff 所需要转换的 xliff 文件
 * @param xliffPath
 *            xliff 文件路径
 * @param monitor
 * @return ;
 */
public IStatus validateXliffFile(String xliffPath, XLFHandler handler, IProgressMonitor monitor) {
	IStatus result = new ReverseConversionValidateWithLibrary3().validate(xliffPath, configBean, monitor);
	if (!result.isOK()) {
		return result;
	}
	// 验证是否存在 xliff 对应的源文件类型的转换器实现
	String fileType = configBean.getFileType();
	Converter converter = getConverter(fileType);
	if (converter != null) {
		result = validateFileNodeInXliff(handler, xliffPath, converter.getType()); // 验证 XLIFF 文件的 file 节点
		if (!result.isOK()) {
			return result;
		}

		setSelectedType(fileType);
		result = Status.OK_STATUS;
	} else {
		result = ValidationStatus.error("xliff 对应的源文件类型的转换器不存在:" + fileType);
	}
	return result;
}
 
Example 6
Source File: TmfOpenTraceHelper.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Open a trace from a trace folder
 *
 * @param destinationFolder
 *            The destination trace folder
 * @param traceName
 *            the trace name
 * @return success or error
 */
private static IStatus openTraceFromFolder(TmfTraceFolder destinationFolder, String traceName) {
    final List<ITmfProjectModelElement> elements = destinationFolder.getChildren();
    TmfTraceElement traceElement = null;
    for (ITmfProjectModelElement element : elements) {
        if (element instanceof TmfTraceElement && element.getName().equals(traceName)) {
            traceElement = (TmfTraceElement) element;
        }
    }
    if (traceElement == null) {
        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(Messages.TmfOpenTraceHelper_TraceNotFound, traceName));
    }
    IStatus status = openFromElement(traceElement);
    if (!status.isOK()) {
        Activator.getDefault().logError("Error opening trace from folder: " + status.getMessage()); //$NON-NLS-1$
    }
    return status;
}
 
Example 7
Source File: NodeJSService.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Downloads a file from url, return the {@link File} on disk where it was saved.
 * 
 * @param url
 * @param monitor
 * @return
 * @throws CoreException
 */
private File download(URL url, String extension, IProgressMonitor monitor) throws CoreException
{
	DownloadManager manager = new DownloadManager();
	IPath path = Path.fromPortableString(url.getPath());
	String name = path.lastSegment();
	File f = new File(FileUtil.getTempDirectory().toFile(), name + extension);
	f.deleteOnExit();
	manager.addURL(url, f);
	IStatus status = manager.start(monitor);
	if (!status.isOK())
	{
		throw new CoreException(status);
	}
	List<IPath> locations = manager.getContentsLocations();
	return locations.get(0).toFile();
}
 
Example 8
Source File: ConversionWizardPage.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
private void validate() {
	IStatus result = Status.OK_STATUS;
	int line = 1;
	for (ConverterViewModel converterViewModel : converterViewModels) {
		result = converterViewModel.validate();
		if (!result.isOK()) {
			break;
		}
		line++;
	}
	if (!result.isOK()) {
		setPageComplete(false);
		setErrorMessage(MessageFormat.format(Messages.getString("ConversionWizardPage.13"), line)
				+ result.getMessage());
	} else {
		setErrorMessage(null);
		setPageComplete(true);
	}
}
 
Example 9
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 10
Source File: TmfStateSystemAnalysisModule.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Retrieve a state system belonging to trace, by passing the ID of the relevant
 * analysis module.
 *
 * This will start the execution of the analysis module, and start the
 * construction of the state system, if needed.
 *
 * @param trace
 *            The trace for which you want the state system
 * @param moduleId
 *            The ID of the state system analysis module
 * @return The state system, or null if there was no match or the module was not
 *         initialized correctly
 */
public static @Nullable ITmfStateSystem getStateSystem(ITmfTrace trace, String moduleId) {
    TmfStateSystemAnalysisModule module = TmfTraceUtils.getAnalysisModuleOfClass(trace, TmfStateSystemAnalysisModule.class, moduleId);
    if (module != null) {
        ITmfStateSystem ss = module.getStateSystem();
        if (ss != null) {
            return ss;
        }
        IStatus status = module.schedule();
        if (status.isOK()) {
            return module.waitForInitialization() ? module.getStateSystem() : null;
        }
    }
    return null;
}
 
Example 11
Source File: CheckJavaValidator.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Verifies that the given check can be interpreted as Java identifier.
 *
 * @param check
 *          the check to validate
 */
@Check
public void checkCheckName(final com.avaloq.tools.ddk.check.check.Check check) {
  final String name = check.getName();
  if (Strings.isEmpty(name)) {
    error(NLS.bind(Messages.CheckJavaValidator_ID_MISSING, CHECK, check.getLabel()), check, locationInFileProvider.getIdentifierFeature(check), IssueCodes.MISSING_ID_ON_CHECK, check.getLabel());

  } else {
    final IStatus status = javaValidatorUtil.checkCheckName(name);
    if (!status.isOK()) {
      issue(status, status.getMessage(), check, locationInFileProvider.getIdentifierFeature(check), IssueCodes.INVALID_CHECK_NAME);
    }
  }
}
 
Example 12
Source File: SARLRuntimeEnvironmentTab.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isValid(ILaunchConfiguration config) {
	final String id = this.accessor.getSREId(config);
	final SREConfigurationBlock blk = getSREConfigurationBlock();
	ISREInstall sre = SARLRuntime.getSREFromId(id);
	if (sre == null) {
		sre = blk.getSelectedSRE();
	}
	final IStatus status;
	if (sre == null) {
		if (Strings.isNullOrEmpty(id)) {
			status = SARLEclipsePlugin.getDefault().createStatus(IStatus.ERROR, Messages.RuntimeEnvironmentTab_7);
		} else {
			status = SARLEclipsePlugin.getDefault().createStatus(IStatus.ERROR, MessageFormat.format(
					Messages.RuntimeEnvironmentTab_6, Strings.nullToEmpty(id)));
		}
	} else {
		status = blk.validate(sre);
	}
	if (status.isOK()) {
		return super.isValid(config) && isValidJREVersion(config);
	}
	setErrorMessage(status.getMessage());
	final Throwable throwable = status.getException();
	if (throwable != null) {
		JDIDebugUIPlugin.log(throwable);
	}
	return false;
}
 
Example 13
Source File: RoutesHandlerV1.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected CFJob handlePut(Route route, HttpServletRequest request, HttpServletResponse response, final String path) {
	final JSONObject jsonData = extractJSONData(request);

	final JSONObject targetJSON = jsonData.optJSONObject(CFProtocolConstants.KEY_TARGET);
	final String domainName = jsonData.optString(CFProtocolConstants.KEY_DOMAIN_NAME, null);
	final String hostName = jsonData.optString(CFProtocolConstants.KEY_HOST, null);

	return new CFJob(request, false) {
		@Override
		protected IStatus performJob() {
			try {
				ComputeTargetCommand computeTargetCommand = new ComputeTargetCommand(this.userId, targetJSON);
				computeTargetCommand.doIt();
				Target target = computeTargetCommand.getTarget();
				if (target == null) {
					return HttpUtil.createErrorStatus(IStatus.WARNING, "CF-TargetNotSet", "Target not set");
				}

				GetDomainsCommand getDomainsCommand = new GetDomainsCommand(target, domainName);
				IStatus getDomainsStatus = getDomainsCommand.doIt();
				if (!getDomainsStatus.isOK())
					return getDomainsStatus;

				CreateRouteCommand createRouteCommand = new CreateRouteCommand(target, getDomainsCommand.getDomains().get(0), hostName);
				IStatus createRouteStatus = createRouteCommand.doIt();
				if (!createRouteStatus.isOK())
					return createRouteStatus;

				return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, createRouteCommand.getRoute().toJSON());
			} catch (Exception e) {
				String msg = NLS.bind("Failed to handle request for {0}", path); //$NON-NLS-1$
				ServerStatus status = new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
				logger.error(msg, e);
				return status;
			}
		}
	};
}
 
Example 14
Source File: ImportStatusDialog.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected static String[] getLabels(final boolean canOpen, IStatus status) {
    List<String> buttons =new ArrayList<>();
    if(canOpen) {
        buttons.add(org.bonitasoft.studio.ui.i18n.Messages.seeDetails);
    } 
    if(status.getSeverity() != IStatus.ERROR) {
        buttons.add(Messages.deploy);
    }
    buttons.add(IDialogConstants.OK_LABEL);
    if(!status.isOK()) {
        buttons.add( Messages.copyToClipboard);
    }
    return buttons.toArray(new String[] {});
}
 
Example 15
Source File: CheckJavaValidator.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Verifies that the given category can be interpreted as Java identifier.
 *
 * @param category
 *          the category to validate
 */
@Check
public void checkCategoryName(final Category category) {
  if (!Strings.isEmpty(category.getName())) {
    IStatus status = javaValidatorUtil.checkCategoryName(category.getName());
    if (!status.isOK()) {
      issue(status, status.getMessage(), category, locationInFileProvider.getIdentifierFeature(category), IssueCodes.INVALID_CATEGORY_NAME);
    }
  }
}
 
Example 16
Source File: JarManifestWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the resource for the specified path.
 *
 * @param path	the path for which the resource should be returned
 * @return the resource specified by the path or <code>null</code>
 */
protected IResource findResource(IPath path) {
	IWorkspace workspace= JavaPlugin.getWorkspace();
	IStatus result= workspace.validatePath(
						path.toString(),
						IResource.ROOT | IResource.PROJECT | IResource.FOLDER | IResource.FILE);
	if (result.isOK() && workspace.getRoot().exists(path))
		return workspace.getRoot().findMember(path);
	return null;
}
 
Example 17
Source File: FileChooserPageBase.java    From ganttproject with GNU General Public License v3.0 5 votes vote down vote up
private static void setStatus(JLabel label, IStatus status) {
  label.setOpaque(true);
  if (status.isOK()) {
    UIUtil.clearErrorLabel(label);
    label.setText(status.getMessage());
  } else {
    UIUtil.setupErrorLabel(label, status.getMessage());
  }
}
 
Example 18
Source File: ExternalLibrariesActionsHelper.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Streamlined process of calculating and installing the dependencies, npm cache cleaning forced by passed flag.
 * <p>
 * <b>IMPORTANT:</b> If <code>npmrcLocation</code> is given (and only then), this method will change the default
 * <code>.npmrc</code> location in the Eclipse preferences and this value will stay in effect after this method
 * returns. Rationale of original implementor:<br>
 * <cite>information about {@code .npmrc} is deep in the NodeProcessBuilder and by design it is not exposed. We
 * could redesign that part and expose it, but it makes sense to assume user selected {@code .npmrc} file while
 * setting up the workspace should be used for further dependencies setups (e.g. quick-fixes in manifests) in this
 * workspace hence we save provided {@code .npmrc} file in the preferences.</cite>
 *
 * @param npmrcLocation
 *            optional path to an <code>.npmrc</code> file to be used during installation of dependencies.
 */
public void cleanAndInstallAllDependencies(Optional<Path> npmrcLocation, SubMonitor monitor,
		MultiStatus multiStatus) {

	try (Measurement m = N4JSDataCollectors.dcInstallHelper.getMeasurement("Install Missing Dependencies")) {

		// configure .npmrc
		if (npmrcLocation.isPresent()) {
			configureNpmrc(npmrcLocation.get(), multiStatus);
		}

		SubMonitor subMonitor = SubMonitor.convert(monitor, 2);

		// remove npms
		multiStatus.merge(maintenanceDeleteNpms(subMonitor.split(1)));

		// install dependencies and force external library workspace reload
		try (Measurement mm = N4JSDataCollectors.dcInstallMissingDeps
				.getMeasurement("Install missing dependencies")) {

			IStatus status = libManager.runNpmYarnInstallOnAllProjects(subMonitor.split(1));
			if (!status.isOK()) {
				multiStatus.merge(status);
			}
		}
	}
}
 
Example 19
Source File: BosArchiveImportStatus.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public List<AbstractProcess> getProcessesWithErrors() {
    final List<AbstractProcess> processes = new ArrayList<AbstractProcess>();
    for (final IStatus child : getChildren()) {
        if (child instanceof ProcessValidationStatus && !child.isOK()) {
            processes.add(((ProcessValidationStatus) child).getProcess());
        }
    }
    return processes;
}
 
Example 20
Source File: WizardNewXtextProjectCreationPage.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected boolean validatePage() {
	if (!super.validatePage())
		return false;
	IStatus status = validateProjectName();
	if (!status.isOK()) {
		setErrorMessage(status.getMessage());
		return false;
	}
	if (languageNameField == null) // See the comment in createControl
		return true;
	if (languageNameField.getText().length() == 0)
		return false;

	status = JavaConventions.validateJavaTypeName(languageNameField.getText(), JavaCore.VERSION_1_5, JavaCore.VERSION_1_5);
	if (!status.isOK()) {
		setErrorMessage(Messages.WizardNewXtextProjectCreationPage_ErrorMessageLanguageName + status.getMessage());
		return false;
	}

	if (!languageNameField.getText().contains(".")) { //$NON-NLS-1$
		setErrorMessage(Messages.WizardNewXtextProjectCreationPage_ErrorMessageLanguageNameWithoutPackage);
		return false;
	}

	if (extensionsField.getText().length() == 0)
		return false;
	if (!PATTERN_EXTENSIONS.matcher(extensionsField.getText()).matches()) {
		setErrorMessage(Messages.WizardNewXtextProjectCreationPage_ErrorMessageExtensions);
		return false;
	}
	JavaVersion javaVersion = JavaVersion.fromBree(breeCombo.getText());
	if (javaVersion != null && !javaVersion.isAtLeast(JavaVersion.JAVA8)) {
		setMessage(Messages.WizardNewXtextProjectCreationPage_MessageAtLeastJava8, IStatus.WARNING);
		return true;
	}
	if (!Sets.newHashSet(JREContainerProvider.getConfiguredBREEs()).contains(breeCombo.getText())) {
		setMessage(Messages.WizardNewXtextProjectCreationPage_eeInfo_0 + breeCombo.getText()
				+ Messages.WizardNewXtextProjectCreationPage_eeInfo_1, IMessageProvider.INFORMATION);
		return true;
	}
	setErrorMessage(null);
	setMessage(null);
	return true;
}