下面列出了org.eclipse.core.runtime.Status#WARNING 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void log(int status, String msg, Exception e) {
if(instance != null) {
Status st = new Status(status, PLUGIN_ID, Status.OK, msg, e);
instance.getLog().log(st);
if(status == Status.ERROR || status == Status.WARNING) {
// StatusManager sm = StatusManager.getManager();
// log("SM handle" + sm);
// if(sm != null) {
//
// sm.handle(st, StatusManager.SHOW);
// }
}
}
else {
if(e != null) System.out.println(msg + ", " + e.toString());
else System.out.println(msg);
}
}
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
ErrorDetectingCLIResult result = new CordovaCLI().version(monitor).convertTo(ErrorDetectingCLIResult.class);
if(result.asStatus().getCode() == CordovaCLIErrors.ERROR_COMMAND_MISSING){
return Status.OK_STATUS;
}
if(result.asStatus().isOK()){
cordovaVersion = Version.parseVersion(result.getMessage()).toString();
return Status.OK_STATUS;
}
} catch (Exception e) {
HybridUI.log(WARNING, "Unable to determine if cordova is available", e);
}
return new Status(Status.WARNING, HybridUI.PLUGIN_ID, "");
}
private static String getSeverityString(int severity) {
switch (severity) {
case Status.OK:
return "OK";
case Status.WARNING:
return "WARNING";
case Status.ERROR:
return "ERROR";
case Status.INFO:
return "INFO";
case Status.CANCEL:
return "CANCEL";
default:
return "? " + severity + " ?";
}
}
/**
* Adds the Dataflow Nature ID to the {@code IProjectDescription} of the provided project.
*/
public static void addDataflowJavaNatureToProject(IProject project, IProgressMonitor monitor)
throws CoreException {
Preconditions.checkNotNull(project);
if (!project.isAccessible()) {
throw new CoreException(new Status(Status.WARNING, DataflowCorePlugin.PLUGIN_ID,
"Can't add the Dataflow nature to closed project " + project.getName()));
}
NatureUtils.addNature(project, DATAFLOW_NATURE_ID, monitor);
}
/**
* Removes the Dataflow Nature ID from the {@code IProjectDescription} of the provided project.
*/
public static void removeDataflowJavaNatureFromProject(IProject project, IProgressMonitor monitor)
throws CoreException {
Preconditions.checkNotNull(project);
if (!project.isAccessible()) {
throw new CoreException(new Status(Status.WARNING, DataflowCorePlugin.PLUGIN_ID,
"Can't remove the Dataflow nature from closed project " + project.getName()));
}
NatureUtils.removeNature(project, DATAFLOW_NATURE_ID, monitor);
}
@Override
public IStatus performSingleDisposal(String articleStoreToString, int count, String mandatorId){
Optional<Identifiable> article =
StoreToStringServiceHolder.get().loadFromString(articleStoreToString);
if (article.isPresent()) {
return performSingleDisposal((IArticle) article.get(), count, mandatorId);
}
return new Status(Status.WARNING, "ch.elexis.core.services",
"No article found [" + articleStoreToString + "]");
}
@Override
public IStatus performSingleReturn(String articleStoreToString, int count, String mandatorId){
Optional<Identifiable> article =
StoreToStringServiceHolder.get().loadFromString(articleStoreToString);
if (article.isPresent()) {
return performSingleReturn((IArticle) article.get(), count, mandatorId);
}
return new Status(Status.WARNING, "ch.elexis.core.services",
"No article found [" + articleStoreToString + "]");
}
public void warn(String message) {
Status messageToLog = new Status(Status.WARNING, Activator.PLUGIN_ID, message);
logMessage(messageToLog);
}
public void warn(String message, Throwable exception) {
Status messageToLog = new Status(Status.WARNING, Activator.PLUGIN_ID, message, exception);
logMessage(messageToLog);
}
protected void logGenmodelError(String resource) {
Status status = new Status(Status.WARNING, BUILDER_ID,
String.format("Cannot execute Genmodel %s. The file contains errors.", resource));
Platform.getLog(BuilderActivator.getDefault().getBundle()).log(status);
}
protected void logStatechartError(final String resource) {
Status status = new Status(Status.WARNING, BUILDER_ID,
String.format("Cannot generate Code for Statechart %s. The file contains errors.", resource));
Platform.getLog(BuilderActivator.getDefault().getBundle()).log(status);
}
/**
* Log a status to the corresponding log-level; does nothing if
* {@link Status#isOK()}
*
* @param prependMessage an optional message to prepend the status
* message
* @param log
* @param status
* @param includeExceptionIfAvailable
* @param logDebugIfOk log to level debug if the status is ok
*/
public static void logStatus(String prependMessage, @NonNull Logger log, @NonNull IStatus status,
boolean includeExceptionIfAvailable, boolean logDebugIfOk) {
if (status.isOK() && !logDebugIfOk) {
return;
}
StringBuilder sb = new StringBuilder();
if (status.isMultiStatus()) {
sb.append("[MULTISTATUS] ");
}
if (prependMessage != null) {
sb.append(prependMessage + " ");
}
sb.append("(c" + status.getCode() + "/s" + status.getSeverity() + ") ");
sb.append(status.getMessage());
String message = sb.toString();
boolean includeException = (includeExceptionIfAvailable && status.getException() != null);
int severity = status.getSeverity();
switch (severity) {
case Status.ERROR:
if (includeException) {
log.error(message, status.getException());
} else {
log.error(message);
}
break;
case Status.WARNING:
if (includeException) {
log.warn(message, status.getException());
} else {
log.warn(message);
}
break;
case Status.INFO:
case Status.CANCEL:
if (includeException) {
log.info(message, status.getException());
} else {
log.info(message);
}
break;
case Status.OK:
log.debug(message);
break;
default:
break;
}
if (status.isMultiStatus()) {
Arrays.asList(status.getChildren()).stream().forEach(c -> logStatus(prependMessage, log, c, true, false));
}
}
@Override
public IStatus performSingleDisposal(IArticle article, int count, String mandatorId){
if (article == null) {
return new Status(Status.ERROR, "ch.elexis.core.services", "Article is null");
}
IStockEntry se = findPreferredStockEntryForArticle(
StoreToStringServiceHolder.getStoreToString(article), mandatorId);
if (se == null) {
return new Status(Status.WARNING, "ch.elexis.core.services",
"No stock entry for article found");
}
if (se.getStock().isCommissioningSystem()) {
boolean suspendOutlay =
configService.getLocal(Preferences.INVENTORY_MACHINE_SUSPEND_OUTLAY,
Preferences.INVENTORY_MACHINE_SUSPEND_OUTLAY_DEFAULT);
if(suspendOutlay) {
return Status.OK_STATUS;
}
int sellingUnit = article.getSellingSize();
boolean isPartialUnitOutput =
(sellingUnit > 0 && sellingUnit < article.getPackageSize());
if (isPartialUnitOutput) {
boolean performPartialOutlay =
configService.get(Preferences.INVENTORY_MACHINE_OUTLAY_PARTIAL_PACKAGES,
Preferences.INVENTORY_MACHINE_OUTLAY_PARTIAL_PACKAGES_DEFAULT);
if (!performPartialOutlay) {
return Status.OK_STATUS;
}
}
return StockCommissioningServiceHolder.get().performArticleOutlay(se, count, null);
} else {
LockResponse lr = LocalLockServiceHolder.get().acquireLockBlocking(se, 1,
new NullProgressMonitor());
if (lr.isOk()) {
int fractionUnits = se.getFractionUnits();
int ve = article.getSellingSize();
int vk = article.getPackageSize();
if (vk == 0) {
if (ve != 0) {
vk = ve;
}
}
if (ve == 0) {
if (vk != 0) {
ve = vk;
}
}
int num = count * ve;
int cs = se.getCurrentStock();
if (vk == ve) {
se.setCurrentStock(cs - count);
} else {
int rest = fractionUnits - num;
while (rest < 0) {
rest = rest + vk;
se.setCurrentStock(cs - 1);
}
se.setFractionUnits(rest);
}
coreModelService.save(se);
LocalLockServiceHolder.get().releaseLock(se);
return Status.OK_STATUS;
}
}
return new Status(Status.WARNING, "ch.elexis.core.services", "Could not acquire lock");
}
@Override
public IStatus performSingleReturn(IArticle article, int count, String mandatorId){
if (article == null) {
return new Status(Status.ERROR, "ch.elexis.core.services", "Article is null");
}
IStockEntry se =
findPreferredStockEntryForArticle(StoreToStringServiceHolder.getStoreToString(article),
null);
if (se == null) {
return new Status(Status.WARNING, "ch.elexis.core.services",
"No stock entry for article found");
}
if (se.getStock().isCommissioningSystem()) {
// updates must happen via manual inputs in the machine
return Status.OK_STATUS;
}
LockResponse lr = LocalLockServiceHolder.get().acquireLockBlocking(se, 1,
new NullProgressMonitor());
if (lr.isOk()) {
int fractionUnits = se.getFractionUnits();
int ve = article.getSellingSize();
int vk = article.getPackageSize();
if (vk == 0) {
if (ve != 0) {
vk = ve;
}
}
if (ve == 0) {
if (vk != 0) {
ve = vk;
}
}
int num = count * ve;
int cs = se.getCurrentStock();
if (vk == ve) {
se.setCurrentStock(cs + count);
} else {
int rest = fractionUnits + num;
while (rest > vk) {
rest = rest - vk;
se.setCurrentStock(cs + 1);
}
se.setFractionUnits(rest);
}
coreModelService.save(se);
LocalLockServiceHolder.get().releaseLock(se);
return Status.OK_STATUS;
}
return new Status(Status.WARNING, "ch.elexis.core.services", "Could not acquire lock");
}
/**
* Adapt the result of an {@link IIdentifiedRunnable} to an {@link IStatus}
*
* @param run
* @return
*/
public static IStatus adapt(Map<String, Serializable> result){
String resultData = (String) result.get(IIdentifiedRunnable.ReturnParameter.RESULT_DATA);
boolean isWarning = result.containsKey(IIdentifiedRunnable.ReturnParameter.MARKER_WARN);
return new Status(isWarning ? Status.WARNING : Status.OK, "unknown", resultData);
}