use of org.eclipse.scout.rt.platform.exception.PlatformError in project scout.rt by eclipse.
the class AbstractForm method interceptInitConfig.
protected final void interceptInitConfig() {
final Holder<RuntimeException> exceptionHolder = new Holder<>(RuntimeException.class, null);
final Holder<PlatformError> errorHolder = new Holder<>(PlatformError.class, null);
m_objectExtensions.initConfig(createLocalExtension(), new Runnable() {
@Override
public void run() {
try {
initConfig();
} catch (RuntimeException e) {
exceptionHolder.setValue(e);
} catch (PlatformError e) {
errorHolder.setValue(e);
}
}
});
if (exceptionHolder.getValue() != null) {
throw exceptionHolder.getValue();
} else if (errorHolder.getValue() != null) {
throw errorHolder.getValue();
}
}
use of org.eclipse.scout.rt.platform.exception.PlatformError in project scout.rt by eclipse.
the class AbstractForm method doCancel.
@Override
public void doCancel() {
if (!isBlockingInternal()) {
return;
}
m_closeType = IButton.SYSTEM_TYPE_CANCEL;
try {
// ensure all fields have the right save-needed-state
checkSaveNeeded();
// find any fields that needs save
P_AbstractCollectingFieldVisitor<IFormField> collector = new P_AbstractCollectingFieldVisitor<IFormField>() {
@Override
public boolean visitField(IFormField field, int level, int fieldIndex) {
if (field.isSaveNeeded()) {
collect(field);
return false;
} else {
return true;
}
}
};
visitFields(collector);
if (collector.getCollectionCount() > 0 && isAskIfNeedSave()) {
int result = MessageBoxes.createYesNoCancel().withDisplayParent(this).withHeader(getCancelVerificationText()).withSeverity(IStatus.INFO).show();
if (result == IMessageBox.YES_OPTION) {
doOk();
return;
} else if (result == IMessageBox.NO_OPTION) {
doClose();
return;
} else {
VetoException e = new VetoException(TEXTS.get("UserCancelledOperation"));
e.consume();
throw e;
}
}
discardStateInternal();
doFinally();
disposeFormInternal();
} catch (RuntimeException | PlatformError e) {
m_closeType = IButton.SYSTEM_TYPE_NONE;
throw BEANS.get(PlatformExceptionTranslator.class).translate(e).withContextInfo("form", getClass().getName());
}
}
use of org.eclipse.scout.rt.platform.exception.PlatformError in project scout.rt by eclipse.
the class AbstractForm method installFormCloseTimer.
/**
* Installs the timer to close the Form once the given seconds elapse
*/
private IFuture<?> installFormCloseTimer(final long seconds) {
final long startMillis = System.currentTimeMillis();
final long delayMillis = TimeUnit.SECONDS.toMillis(seconds);
return ModelJobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
final long elapsedMillis = System.currentTimeMillis() - startMillis;
final long remainingSeconds = TimeUnit.MILLISECONDS.toSeconds(delayMillis - elapsedMillis);
if (!isCloseTimerArmed()) {
setSubTitle(null);
} else if (remainingSeconds > 0) {
setSubTitle("" + remainingSeconds);
} else {
// cancel the periodic action
setCloseTimerArmed(false);
try {
interceptCloseTimer();
} catch (RuntimeException | PlatformError e) {
throw BEANS.get(PlatformExceptionTranslator.class).translate(e).withContextInfo("form", getClass().getName());
}
}
}
}, ModelJobs.newInput(ClientRunContexts.copyCurrent()).withName("Close timer").withExceptionHandling(null, false).withExecutionTrigger(Jobs.newExecutionTrigger().withSchedule(SimpleScheduleBuilder.repeatSecondlyForever())));
}
use of org.eclipse.scout.rt.platform.exception.PlatformError in project scout.rt by eclipse.
the class AbstractForm method exportFormData.
@Override
public void exportFormData(final AbstractFormData target) {
// locally declared form properties
Map<String, Object> properties = BeanUtility.getProperties(this, AbstractForm.class, new FormDataPropertyFilter());
BeanUtility.setProperties(target, properties, false, null);
// properties in extensions of form
exportExtensionProperties(this, target);
final Set<IFormField> exportedFields = new HashSet<IFormField>();
// all fields
Map<Integer, Map<String, AbstractFormFieldData>> /* qualified field id */
breadthFirstMap = target.getAllFieldsRec();
for (Map<String, AbstractFormFieldData> /* qualified field id */
targetMap : breadthFirstMap.values()) {
for (Map.Entry<String, AbstractFormFieldData> e : targetMap.entrySet()) {
String fieldQId = e.getKey();
AbstractFormFieldData data = e.getValue();
FindFieldByFormDataIdVisitor v = new FindFieldByFormDataIdVisitor(fieldQId, this);
visitFields(v);
IFormField f = v.getField();
if (f != null) {
// field properties
properties = BeanUtility.getProperties(f, AbstractFormField.class, new FormDataPropertyFilter());
BeanUtility.setProperties(data, properties, false, null);
exportExtensionProperties(f, data);
// field state
f.exportFormFieldData(data);
// remember exported fields
exportedFields.add(f);
} else {
LOG.warn("Cannot find field with id '{}' in form '{}' for DTO '{}'.", fieldQId, getClass().getName(), data.getClass().getName());
}
}
}
// visit remaining fields (there could be an extension with properties e.g. on a groupbox)
final Holder<RuntimeException> exHolder = new Holder<>(RuntimeException.class);
final Holder<PlatformError> errorHolder = new Holder<>(PlatformError.class);
visitFields(new IFormFieldVisitor() {
@Override
public boolean visitField(IFormField field, int level, int fieldIndex) {
if (exportedFields.contains(field)) {
// already exported -> skip
return true;
}
final IForm formOfField = field.getForm();
if (formOfField == null) {
// either form has not been initialized or the field is part of a composite field, that does not override setForminternal -> skip
LOG.info("Extension properties are not exported for fields on which getForm() returns null. " + "Ensure that the form is initialized and that the field's parent invokes field.setFormInternal(IForm) [exportingForm={}, field={}]", AbstractForm.this.getClass().getName(), field.getClass().getName());
return true;
}
if (formOfField != AbstractForm.this) {
// field belongs to another form -> skip
return true;
}
try {
exportExtensionProperties(field, target);
} catch (RuntimeException e) {
exHolder.setValue(e);
} catch (PlatformError e) {
errorHolder.setValue(e);
}
return exHolder.getValue() == null && errorHolder.getValue() == null;
}
});
if (exHolder.getValue() != null) {
throw exHolder.getValue();
} else if (errorHolder.getValue() != null) {
throw errorHolder.getValue();
}
}
use of org.eclipse.scout.rt.platform.exception.PlatformError in project scout.rt by eclipse.
the class AbstractPage method execDataChanged.
/**
* Called by the data change listener registered with this page (and the current desktop) through
* {@link #registerDataChangeListener(Object...)}. Use this callback method to react to data change events by
* reloading current data, or throwing away cached data etc.
* <p>
* Subclasses can override this method.<br/>
* This default implementation does the following:
* <ol>
* <li>if this page is an ancestor of the selected page (or is selected itself) and this page is in the active
* outline, a full re-load of the page is performed
* <li>else the children of this page are marked dirty and the page itself is unloaded
* </ol>
*
* @see IDesktop#dataChanged(Object...)
*/
@ConfigOperation
@Order(55)
protected void execDataChanged(Object... dataTypes) {
if (getTree() == null) {
return;
}
//
HashSet<ITreeNode> pathsToSelections = new HashSet<ITreeNode>();
for (ITreeNode node : getTree().getSelectedNodes()) {
ITreeNode tmp = node;
while (tmp != null) {
pathsToSelections.add(tmp);
tmp = tmp.getParentNode();
}
}
IDesktop desktop = ClientSessionProvider.currentSession().getDesktop();
final boolean isActiveOutline = (desktop != null ? desktop.getOutline() == this.getOutline() : false);
final boolean isRootNode = pathsToSelections.isEmpty() && getTree() != null && getTree().getRootNode() == this;
if (isActiveOutline && (pathsToSelections.contains(this) || isRootNode)) {
try {
// TODO [7.0] fko: maybe remove when bookmarks can be done on outline level? (currently only pages)
if (isRootNode) {
this.reloadPage();
} else /*
* Ticket 77332 (deleting a node in the tree) also requires a reload So
* the selected and its ancestor nodes require same processing
*/
if (desktop != null) {
// NOSONAR
Bookmark bm = desktop.createBookmark();
setChildrenDirty(true);
// activate bookmark without activating the outline, since this would hide active tabs.
desktop.activateBookmark(bm, false);
}
} catch (RuntimeException | PlatformError e) {
BEANS.get(ExceptionHandler.class).handle(e);
}
} else {
// not active outline OR not on selection path
setChildrenDirty(true);
if (isExpanded()) {
setExpanded(false);
}
try {
if (isChildrenLoaded()) {
getTree().unloadNode(this);
}
} catch (RuntimeException | PlatformError e) {
BEANS.get(ExceptionHandler.class).handle(e);
}
}
}
Aggregations