/** * Load a monitor from persistent storage. Logs an error if it can't be loaded. * * @param memento */ private void loadMonitor(IMemento memento) { try { IMonitorControl monitor = new MonitorControl(memento.getID()); if (monitor.load()) { fMonitorControlsToStart.add(monitor); } addMonitorControl(monitor); } catch (CoreException e) { LMLMonitorCorePlugin.log(e.getLocalizedMessage()); } }
private void restorePageFromMemento() { if (fPageState != null) { int bestActivation = -1; IMemento restorePageMemento = null; IMemento[] children = fPageState.getChildren(MEMENTO_TYPE); for (int i = 0; i < children.length; i++) { IMemento pageMemento = children[i]; if (pageMemento.getString(MEMENTO_KEY_RESTORE) != null) { Integer lastActivation = pageMemento.getInteger(MEMENTO_KEY_LAST_ACTIVATION); if (lastActivation != null && lastActivation.intValue() > bestActivation) { bestActivation = lastActivation.intValue(); restorePageMemento = pageMemento; } } } if (restorePageMemento != null) { showEmptySearchPage(restorePageMemento.getID()); } } }
private void restoreState() { String mementoString = Activator.getInstance().getPreferenceStore().getString("expressionMemento"); if (mementoString == null || "".equals(mementoString)) return; StringReader mementoReader = new StringReader(mementoString); try { XMLMemento memento = XMLMemento.createReadRoot(mementoReader); IMemento[] workingSets = memento.getChildren("workingSet"); for (int i = 0; i < workingSets.length; i++) { IMemento workingSetMemento = workingSets[i]; String workingSetId = workingSetMemento.getID(); if (workingSetId == null || "".equals(workingSetId)) { StatusManager.getManager() .handle(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "missing working set id")); continue; } String patternString = workingSetMemento.getString("pattern"); if (patternString == null || "".equals(patternString)) { StatusManager.getManager() .handle(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "missing pattern")); continue; } Pattern pattern = null; try { pattern = Pattern.compile(patternString); } catch (PatternSyntaxException e) { StatusManager.getManager() .handle(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "bad pattern", e)); continue; } IMemento rootMemento = memento.getChild("root"); if (rootMemento == null) { StatusManager.getManager() .handle(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "missing root memento")); continue; } String factoryId = rootMemento.getString("factoryID"); if (factoryId == null || "".equals(factoryId)) { StatusManager.getManager() .handle(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "missing root memento")); continue; } IElementFactory factory = PlatformUI.getWorkbench().getElementFactory(factoryId); if (factory == null) { StatusManager.getManager() .handle( new Status( IStatus.ERROR, Activator.PLUGIN_ID, "cannot create element factory: " + factoryId)); continue; } IAdaptable item = factory.createElement(rootMemento); if (item == null) { StatusManager.getManager() .handle( new Status( IStatus.ERROR, Activator.PLUGIN_ID, "cannot create element from factory: " + factoryId)); continue; } Record record = new Record(); record.pattern = pattern; record.root = item; map.put(workingSetId, record); } } catch (WorkbenchException e) { StatusManager.getManager() .handle( new Status( IStatus.ERROR, Activator.PLUGIN_ID, "problem restoring working set states", e)); } }