use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class BookmarkUtility method activateBookmark.
/**
* Load a {@link Bookmark} on the specified {@link IDesktop} model.
* <p>
* First the specific {@link Bookmark#getOutlineClassName()} is evaluated and, if activateOutline is true, activated.
* Afterwards every page from the {@link Bookmark#getPath()} will be selected (respecting the
* {@link AbstractPageState}).
* </p>
* Finally the path will be expanded. Possible exceptions might occur if no outline is set in the {@link Bookmark} or
* the outline is not available.
*/
public static void activateBookmark(IDesktop desktop, Bookmark bm, boolean activateOutline) {
if (bm.getOutlineClassName() == null) {
return;
}
IOutline outline = BookmarkUtility.resolveOutline(desktop.getAvailableOutlines(), bm.getOutlineClassName());
if (outline == null) {
throw new ProcessingException("outline '" + bm.getOutlineClassName() + "' was not found");
}
if (!(outline.isVisible() && outline.isEnabled())) {
throw new VetoException(TEXTS.get("BookmarkActivationFailedOutlineNotAvailable", outline.getTitle()));
}
if (activateOutline) {
desktop.activateOutline(outline);
}
try {
outline.setTreeChanging(true);
//
IPage<?> parentPage = outline.getRootPage();
boolean pathFullyRestored = true;
List<AbstractPageState> path = bm.getPath();
AbstractPageState parentPageState = path.get(0);
boolean resetViewAndWarnOnFail = bm.getId() != 0;
for (int i = 1; i < path.size(); i++) {
// try to find correct child page (next parentPage)
IPage<?> childPage = null;
AbstractPageState childState = path.get(i);
if (parentPageState instanceof TablePageState) {
TablePageState tablePageState = (TablePageState) parentPageState;
if (parentPage instanceof IPageWithTable) {
IPageWithTable tablePage = (IPageWithTable) parentPage;
childPage = bmLoadTablePage(tablePage, tablePageState, false, resetViewAndWarnOnFail);
}
} else if (parentPageState instanceof NodePageState) {
NodePageState nodePageState = (NodePageState) parentPageState;
if (parentPage instanceof IPageWithNodes) {
IPageWithNodes nodePage = (IPageWithNodes) parentPage;
childPage = bmLoadNodePage(nodePage, nodePageState, childState, resetViewAndWarnOnFail);
}
}
// next
if (childPage != null) {
parentPage = childPage;
parentPageState = childState;
} else if (i < path.size()) {
pathFullyRestored = false;
break;
}
}
if (pathFullyRestored) {
if (parentPageState instanceof TablePageState && parentPage instanceof IPageWithTable) {
bmLoadTablePage((IPageWithTable) parentPage, (TablePageState) parentPageState, true, resetViewAndWarnOnFail);
} else if (parentPage instanceof IPageWithNodes) {
bmLoadNodePage((IPageWithNodes) parentPage, (NodePageState) parentPageState, null, resetViewAndWarnOnFail);
}
}
/*
* Expansions of the restored tree path
*/
IPage<?> p = parentPage;
// last element
if (pathFullyRestored && parentPageState.isExpanded() != null) {
p.setExpanded(parentPageState.isExpanded());
} else {
if (!(p instanceof IPageWithTable)) {
p.setExpanded(true);
}
}
// ancestor elements
p = p.getParentPage();
while (p != null) {
p.setExpanded(true);
p = p.getParentPage();
}
outline.selectNode(parentPage, false);
} finally {
outline.setTreeChanging(false);
}
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class FileService method getRemoteFile.
@Override
public File getRemoteFile(String dir, String simpleName, Locale locale, boolean checkCache) {
RemoteFile spec = null;
File f = null;
if (locale != null && simpleName != null && simpleName.lastIndexOf('.') != -1) {
String filename = simpleName;
String language = locale.toString().replaceAll("__", "_");
String prefix = filename.substring(0, filename.lastIndexOf('.')) + "_";
String suffix = filename.substring(filename.lastIndexOf('.'));
filename = prefix + language + suffix;
File test = getFileLocation(dir, filename, false);
while (!test.exists()) {
if (language.indexOf('_') == -1) {
filename = simpleName;
break;
}
language = language.substring(0, language.lastIndexOf('_'));
filename = prefix + language + suffix;
test = getFileLocation(dir, filename, false);
}
f = getFileLocation(dir, filename, false);
spec = new RemoteFile(dir, filename, locale, 0L);
} else {
f = getFileLocation(dir, simpleName, false);
spec = new RemoteFile(dir, simpleName, locale, 0L);
}
if (f.exists()) {
spec.setLastModified(f.lastModified());
}
//
if (checkCache) {
IRemoteFileService svc = BEANS.get(IRemoteFileService.class);
spec = svc.getRemoteFile(spec);
try {
if (spec.getName() != null && !spec.getName().equalsIgnoreCase(f.getName())) {
if (locale != null && f.getName().length() > spec.getName().length()) {
// if local file has longer name (including locale), this means that
// this file was deleted on the server
f.delete();
}
f = getFileLocation(spec.getDirectory(), spec.getName(), false);
}
if (spec.exists() && spec.hasContent()) {
try (OutputStream out = new FileOutputStream(f)) {
spec.writeData(out);
}
f.setLastModified(spec.getLastModified());
} else if (!spec.exists()) {
f.delete();
}
} catch (IOException e) {
throw new ProcessingException("error writing remote file in local store", e);
}
}
return f;
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class FileService method syncRemoteFilesInternal.
private void syncRemoteFilesInternal(String serverFolderPath, FilenameFilter filter, boolean useServerFolderStructureOnClient) {
IRemoteFileService svc = BEANS.get(IRemoteFileService.class);
String[][] realFiles = getFiles(serverFolderPath, filter, useServerFolderStructureOnClient);
RemoteFile[] existingFileInfoOnClient = new RemoteFile[realFiles.length];
for (int i = 0; i < realFiles.length; i++) {
RemoteFile rf = new RemoteFile(realFiles[i][0], realFiles[i][1], 0);
String dir = m_rootPath == null ? realFiles[i][0] : "";
File f = getFileLocation(dir, realFiles[i][1], false);
if (f.exists()) {
rf.setLastModified(f.lastModified());
}
existingFileInfoOnClient[i] = rf;
}
existingFileInfoOnClient = svc.getRemoteFiles(serverFolderPath, filter, existingFileInfoOnClient);
for (RemoteFile spec : existingFileInfoOnClient) {
String fileDirectory = useServerFolderStructureOnClient ? spec.getDirectory() : null;
File f = getFileLocation(fileDirectory, spec.getName(), false);
if (spec.exists() && spec.hasContent()) {
try {
if (spec.hasMoreParts()) {
// file is splitted - get all parts
int counter = 0;
long fileDate = spec.getLastModified();
File part = getFileLocation(fileDirectory, spec.getName() + "." + counter, false);
try (OutputStream out = new FileOutputStream(part)) {
spec.writeData(out);
}
part.setLastModified(fileDate);
RemoteFile specPart = spec;
while (specPart.hasMoreParts()) {
counter++;
part = getFileLocation(fileDirectory, spec.getName() + "." + counter, false);
if (!part.exists() || fileDate != part.lastModified()) {
specPart = svc.getRemoteFilePart(spec, counter);
try (OutputStream out = new FileOutputStream(part)) {
specPart.writeData(out);
}
part.setLastModified(fileDate);
} else {
// resuming canceled part: nothing to do
}
}
// put together
counter = 0;
f = getFileLocation(fileDirectory, spec.getName(), false);
try (OutputStream out = new FileOutputStream(f)) {
part = getFileLocation(fileDirectory, spec.getName() + "." + counter, false);
while (part.exists()) {
try (InputStream in = new FileInputStream(part)) {
byte[] buf = new byte[102400];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.flush();
}
part.delete();
counter++;
part = getFileLocation(fileDirectory, spec.getName() + "." + counter, false);
}
}
f.setLastModified(fileDate);
} else {
// normal files
try (OutputStream out = new FileOutputStream(f)) {
spec.writeData(out);
}
f.setLastModified(spec.getLastModified());
}
} catch (IOException e) {
throw new ProcessingException("error writing remote file in local store", e);
}
} else if (!spec.exists()) {
f.delete();
}
}
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class FileSystemUserPreferencesStorageService method loadFromDisk.
protected Properties loadFromDisk(File prefsLocation) {
LOG.debug("loading preferences from file '{}'.", prefsLocation.getAbsolutePath());
Properties result = new Properties();
try (InputStream input = new BufferedInputStream(new FileInputStream(prefsLocation))) {
result.load(input);
} catch (IOException e) {
throw new ProcessingException("Error loading preferences from file '" + prefsLocation.getAbsolutePath() + "'.", e);
}
return result;
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class AbstractForm method storePropertiesToXml.
/**
* Adds a <property> element for every given property to the parent element.
*
* @see #loadPropertiesFromXml(Element)
*/
protected void storePropertiesToXml(Element parent, Map<String, Object> props) {
for (Entry<String, Object> entry : props.entrySet()) {
try {
Element xProp = parent.getOwnerDocument().createElement("property");
parent.appendChild(xProp);
xProp.setAttribute("name", entry.getKey());
XmlUtility.setObjectAttribute(xProp, "value", entry.getValue());
} catch (Exception e) {
throw new ProcessingException("property " + entry.getKey() + " with value " + entry.getValue(), e);
}
}
}
Aggregations