@Override public void init ( final IViewSite site, final IMemento memento ) throws PartInitException { if ( memento != null ) { this.connectionId = memento.getString ( CONNECTION_ID ); this.connectionUri = memento.getString ( CONNECTION_URI ); } super.init ( site, memento ); try { // it is OK to fail at this stage reInitializeConnection ( this.connectionId, this.connectionUri ); } catch ( final Exception e ) { logger.warn ( "init () - couldn't recreate connection", e ); //$NON-NLS-1$ // just reset all values this.connectionId = null; this.connectionUri = null; this.connectionService = null; this.connectionTracker = null; } }
public void saveTo ( final IMemento memento ) { if ( memento == null ) { return; } { final IMemento tableMemento = memento.createChild ( "tableCols" ); //$NON-NLS-1$ for ( int i = 0; i < this.viewer.getTree ().getColumnCount (); i++ ) { final TreeColumn col = this.viewer.getTree ().getColumn ( i ); tableMemento.putInteger ( "col_" + i, col.getWidth () ); //$NON-NLS-1$ } } for ( final ListEntry entry : this.list.getItems () ) { final Item item = entry.getItem (); item.saveTo ( memento.createChild ( "item" ) ); //$NON-NLS-1$ } }
@Override public void saveState(IMemento memento) { // Scroll lock memento.putBoolean("scrollLock", scrollLock); // Limit log chars memento.putInteger("limitLogChars", limitLogChars); // Activate on new events memento.putBoolean("activateOnNewEvents", activateOnNewEvents); // Column order memento.putString("columnOrder", Arrays.toString(tableViewer.getTable().getColumnOrder())); // Column information for (ColumnInfo columnInfo : columnInfos) { IMemento columnInfoMemento = memento.createChild("columnInfo"); columnInfoMemento.putString("name", columnInfo.getName()); columnInfoMemento.putBoolean("visible", columnInfo.isVisible()); columnInfoMemento.putInteger("size", columnInfo.getSize()); } super.saveState(memento); }
@Override public void saveState(IMemento memento) { super.saveState(memento); try { final List<IScanPathModel> models = getPath(); stash.stash(models); for (String propName : trees.keySet()) { IStashing tstash = ServiceHolder.getStashingService().createStash(propName+".json"); tstash.stash(trees.get(propName)); } } catch (Exception ne) { logger.error("Cannot save generators to memento!", ne); } }
/** * Saves the code folding state into the given memento. */ public void saveCodeFolding(IMemento memento) { // The annotation model might be null if the editor opened an storage input // instead of a file input. if (projectionAnnotationModel == null) { return; } Iterator<?> annotationIt = projectionAnnotationModel.getAnnotationIterator(); while (annotationIt.hasNext()) { ProjectionAnnotation annotation = (ProjectionAnnotation) annotationIt.next(); IMemento annotationMemento = memento.createChild(ANNOTATION); Position position = projectionAnnotationModel.getPosition(annotation); annotationMemento.putBoolean(IS_COLLAPSED, annotation.isCollapsed()); annotationMemento.putInteger(OFFSET, position.offset); annotationMemento.putInteger(LENGTH, position.length); } }
/** * <p> * Restores the code folding state from a XML file in the state location. * </p> * * @param uriString the key to determine the file to load the state from */ public void restoreCodeFoldingStateFromFile(String uriString) { final File stateFile = getCodeFoldingStateFile(uriString); if (stateFile == null || !stateFile.exists()) { calculatePositions(); return; } SafeRunner.run(new SafeRunnable("Unable to read code folding state. The state will be reset.") { public void run() throws Exception { FileInputStream input = new FileInputStream(stateFile); BufferedReader reader = new BufferedReader(new InputStreamReader(input, "utf-8")); IMemento memento = XMLMemento.createReadRoot(reader); reader.close(); String sourceText = sourceViewer.getDocument().get(); if (memento.getString(VERIFY_KEY).equals(makeMD5(sourceText))) { restoreCodeFolding(memento); } else { calculatePositions(); } } }); }
private void populateWithStateToSave(final VSUser user, final IMemento memento) { for (final Iterator it = user.workspaces.keySet().iterator(); it.hasNext();) { final String workspaceName = (String) it.next(); final VSWorkspace workspace = (VSWorkspace) user.workspaces.get(workspaceName); final IMemento workspaceMemento = memento.createChild(WORKSPACE_CHILDREN, workspace.name); for (final Iterator expandedPathsIt = workspace.expandedPaths.iterator(); expandedPathsIt.hasNext();) { final String path = (String) expandedPathsIt.next(); final IMemento expandedMemento = workspaceMemento.createChild(EXPANDED_CHILDREN); expandedMemento.putString(PATH_KEY, path); } if (workspace.selectedPath != null) { final IMemento selectedMemento = workspaceMemento.createChild(SELECTED_CHILD); selectedMemento.putString(PATH_KEY, workspace.selectedPath); } } }
public void setSavedState(final IMemento memento) { servers.clear(); if (memento == null) { return; } final IMemento folderControlMemento = memento.getChild(FOLDER_CONTROL_CHILD); if (folderControlMemento == null) { return; } final IMemento[] serverMementos = folderControlMemento.getChildren(SERVER_CHILDREN); if (serverMementos != null) { for (int i = 0; i < serverMementos.length; i++) { if (serverMementos[i].getID() != null) { final VSServer server = new VSServer(serverMementos[i].getID()); setSavedState(server, serverMementos[i]); servers.put(server.guid, server); } } } }
private void setSavedState(final VSUser user, final IMemento memento) { final IMemento[] workspaceMementos = memento.getChildren(WORKSPACE_CHILDREN); if (workspaceMementos != null) { for (int i = 0; i < workspaceMementos.length; i++) { if (workspaceMementos[i].getID() != null) { final VSWorkspace workspace = new VSWorkspace(workspaceMementos[i].getID()); final IMemento[] expandedMementos = workspaceMementos[i].getChildren(EXPANDED_CHILDREN); if (expandedMementos != null) { restoreExpanded(workspace, expandedMementos); } final IMemento selectedMemento = workspaceMementos[i].getChild(SELECTED_CHILD); if (selectedMemento != null) { restoreSelected(workspace, selectedMemento); } user.workspaces.put(workspace.name, workspace); } } } }
@Override public void saveState(final IMemento memento) { super.saveState(memento); final IMemento settings = memento.createChild(PARTICIPANT_SETTINGS); // persist the paths of all resources that we're currently // synchronizing, // we'll use these paths to restore the synchronization view final IResource[] resources = getResources(); final StringBuffer resourceList = new StringBuffer(); for (int i = 0; i < resources.length; i++) { if (i > 0) { resourceList.append("|"); //$NON-NLS-1$ } resourceList.append(resources[i].getLocation().toOSString()); if (resources[i].getType() != IResource.FILE) { resourceList.append("/"); //$NON-NLS-1$ } } settings.putString(PARTICIPANT_SETTINGS_RESOURCES, resourceList.toString()); }
/** * Initialize the editor. Called when first created or when logged in to * server. */ private void init(final IMemento memento) { folderControl.populateTreeUsingServerRoot(); if (memento != null) { folderControlViewState.setSavedState(memento); } final ServerItemPath[] expanded = folderControlViewState.getPreviouslyExpandedPaths(); if (expanded != null && expanded.length > 0) { folderControl.setExpandedItems(expanded); } else { folderControl.expandToLevel(TFSItemFactory.getRoot(), 1); } final ServerItemPath selected = folderControlViewState.getPreviouslySelectedPath(); if (selected != null) { folderControl.setSelectedItem(selected); } else { folderControl.setSelectedItem(ServerItemPath.ROOT); } handleFolderSelection(folderControl.getSelection()); }
/** * Load history elements from memento. * * @param memento * memento from which the history will be retrieved */ public void load(IMemento memento) { XMLMemento historyMemento = (XMLMemento) memento .getChild(rootNodeName); if (historyMemento == null) { return; } IMemento[] mementoElements = historyMemento .getChildren(infoNodeName); for (int i = 0; i < mementoElements.length; ++i) { IMemento mementoElement = mementoElements[i]; Object object = restoreItemFromMemento(mementoElement); if (object != null) { historyList.add(object); } } }
private static void createDefaultLayer_10_Map(final IMemento xml) { createLayerXml_120_Default(xml, true, true, 1.0f, MapDefaultLayer.ID_STARS); createLayerXml_120_Default(xml, true, true, 1.0f, MapDefaultLayer.ID_ATMOSPHERE); createLayerXml_120_Default(xml, true, true, 1.0f, MapDefaultLayer.ID_NASA_BLUE_MARBLE_IMAGE); createLayerXml_120_Default(xml, true, true, 1.0f, MapDefaultLayer.ID_BLUE_MARBLE_WMS_2004); createLayerXml_120_Default(xml, true, true, 1.0f, MapDefaultLayer.ID_I_CUBED_LANDSAT); createLayerXml_120_Default(xml, false, true, 1.0f, MapDefaultLayer.ID_USDA_NAIP); createLayerXml_120_Default(xml, false, true, 1.0f, MapDefaultLayer.ID_USDA_NAIP_USGS); createLayerXml_120_Default(xml, true, true, 1.0f, MapDefaultLayer.ID_MS_VIRTUAL_EARTH_AERIAL); createLayerXml_120_Default(xml, true, true, 1.0f, MapDefaultLayer.ID_BING_IMAGERY); createLayerXml_120_Default(xml, false, true, 1.0f, MapDefaultLayer.ID_USGS_TOPOGRAPHIC_MAPS_1_250K); createLayerXml_120_Default(xml, false, true, 1.0f, MapDefaultLayer.ID_USGS_TOPOGRAPHIC_MAPS_1_100K); createLayerXml_120_Default(xml, false, true, 1.0f, MapDefaultLayer.ID_USGS_TOPOGRAPHIC_MAPS_1_24K); createLayerXml_120_Default(xml, false, true, 1.0f, MapDefaultLayer.ID_USGS_URBAN_AREA_ORTHO); createLayerXml_120_Default(xml, true, true, 1.0f, MapDefaultLayer.ID_POLITICAL_BOUNDARIES); createLayerXml_120_Default(xml, false, true, 1.0f, MapDefaultLayer.ID_OPEN_STREET_MAP); createLayerXml_120_Default(xml, false, true, 1.0f, MapDefaultLayer.ID_EARTH_AT_NIGHT); }
private static void readXml_Date( final IMemento xmlProperty, final TourFilterProperty filterProperty, final int fieldNo) { final LocalDateTime defaultDate = fieldNo == 1 ? TourFilterProperty.DEFAULT_DATE_1 : TourFilterProperty.DEFAULT_DATE_2; final int year = Util.getXmlInteger(xmlProperty, ATTR_DATE_YEAR + fieldNo, defaultDate.getYear()); final int month = Util.getXmlInteger(xmlProperty, ATTR_DATE_MONTH + fieldNo, defaultDate.getMonthValue()); final int day = Util.getXmlInteger(xmlProperty, ATTR_DATE_DAY + fieldNo, defaultDate.getDayOfMonth()); final LocalDateTime date = LocalDateTime.of(year, month, day, 0, 0); if (fieldNo == 1) { filterProperty.dateTime1 = date; } else { filterProperty.dateTime2 = date; } }
private static void saveState_URI( final URI[] location, final IMetadataRepositoryManager metaManager, final IMemento xmlRepositories, final boolean isEnabled) { for (final URI uri : location) { final IMemento xmlRepo = xmlRepositories.createChild(TAG_REPOSITORY); final String nickName = metaManager.getRepositoryProperty(uri, IRepository.PROP_NICKNAME); xmlRepo.putString(ATTR_URI, uri.toASCIIString()); xmlRepo.putString(ATTR_NICK_NAME, nickName); xmlRepo.putBoolean(ATTR_IS_ENABLED, isEnabled); } }
public IAdaptable createElement(IMemento memento) { String uriStr = memento.getString(EMF_URI); if (uriStr == null) { return null; } URI uri = URI.createURI(uriStr); ResourceSet resourceSet = DiagramPartitioningUtil.getSharedDomain().getResourceSet(); Resource resource = resourceSet.getResource(uri, false); if (resource == null) resource = resourceSet.createResource(uri); try { resource.load(Collections.emptyMap()); } catch (IOException e) { e.printStackTrace(); } Diagram diagram = (Diagram) resource.getEObject(uri.fragment()); return new DiagramEditorInput(diagram); }
/** * Associate projects with branch. The specified memento must the one * previously returned from a call to {@link #snapshot()}. * * @see #snapshot() * @param memento * @return this tracker */ public BranchProjectTracker save(final IMemento memento) { if (!(memento instanceof XMLMemento)) throw new IllegalArgumentException("Invalid memento"); //$NON-NLS-1$ String branch = memento.getString(KEY_BRANCH); IPreferenceStore store = Activator.getDefault().getPreferenceStore(); String pref = getPreference(branch); StringWriter writer = new StringWriter(); try { ((XMLMemento) memento).save(writer); store.setValue(pref, writer.toString()); } catch (IOException e) { Activator.logError("Error writing branch-project associations", e); //$NON-NLS-1$ } return this; }
private static void createLayerXml_120_Default( final IMemento xmlCategory, final boolean isEnabled, final boolean canSetOpacity, final float opacity, final String defaultLayerId) { final DefaultLayer mapDefaultLayer = MapDefaultLayer.getLayer(defaultLayerId); if (mapDefaultLayer == null) { return; } final IMemento xmlLayer = xmlCategory.createChild(TAG_LAYER); xmlLayer.putString(ATTR_ID, defaultLayerId); xmlLayer.putBoolean(ATTR_IS_ENABLED, isEnabled); xmlLayer.putBoolean(ATTR_IS_DEFAULT_LAYER, true); // opacity xmlLayer.putFloat(ATTR_OPACITY, opacity); xmlLayer.putBoolean(ATTR_CAN_SET_OPACITY, canSetOpacity); }
public void restoreState(IPresentationSerializer context, IMemento memento) { if (PresentationPlugin.DEBUG_STATE) { System.out.println(getDebugPartName() + ":restoreState"); } /* * we do not use setFlag() here to prevent layout and redraw on startup */ Integer flag = memento.getInteger("toolbarVisible"); if (flag != null) { stackFlags.set(F_TOOLBAR_VISIBLE, flag.intValue() == 1); } else { // TODO read from theme setting stackFlags.set(F_TOOLBAR_VISIBLE, true); } flag = memento.getInteger("tabAreaVisible"); if (flag != null) { stackFlags.set(F_TAB_AREA_VISIBLE, flag.intValue() == 1); } else { // TODO read from theme setting stackFlags.set(F_TAB_AREA_VISIBLE, true); } tabArea.restoreState(context, memento, this); }
private static void createXml_FromTrackConfig(final Map25TrackConfig config, final IMemento xmlTourTracks) { // <Track> final IMemento xmlConfig = xmlTourTracks.createChild(TAG_TRACK); { xmlConfig.putString(ATTR_ID, config.id); xmlConfig.putString(ATTR_CONFIG_NAME, config.name); xmlConfig.putInteger(ATTR_ANIMATION_TIME, config.animationTime); // <Outline> final IMemento xmlOutline = Util.setXmlRgb(xmlConfig, TAG_OUTLINE, config.outlineColor); { xmlOutline.putFloat(ATTR_OUTLINE_WIDTH, config.outlineWidth); } } }
private static void readXml_Time( final IMemento xmlProperty, final TourFilterProperty filterProperty, final int fieldNo) { final LocalDateTime defaultTime = fieldNo == 1 ? TourFilterProperty.DEFAULT_DATE_1 : TourFilterProperty.DEFAULT_DATE_2; final int hour = Util.getXmlInteger(xmlProperty, ATTR_TIME_HOUR + fieldNo, defaultTime.getHour()); final int minute = Util.getXmlInteger(xmlProperty, ATTR_TIME_MINUTE + fieldNo, defaultTime.getMinute()); final LocalDateTime date = LocalDateTime.now().withHour(hour).withMinute(minute); if (fieldNo == 1) { filterProperty.dateTime1 = date; } else { filterProperty.dateTime2 = date; } }
public static UiBinderSubtypeToOwnerIndex load(IMemento memento) throws PersistenceException { UiBinderSubtypeToOwnerIndex index = new UiBinderSubtypeToOwnerIndex(); boolean hadException = false; for (IMemento childMemento : memento.getChildren(KEY_UIBINDER_SUBTYPE_AND_OWNER_ENTRY)) { try { UiBinderSubtypeAndOwner subtypeAndOwner = UiBinderSubtypeAndOwner.load(childMemento); if (subtypeAndOwner != null) { index.setOwnerType(subtypeAndOwner); } } catch (PersistenceException e) { CorePluginLog.logError(e, "Error loading persisted index entry."); hadException = true; } } if (hadException) { throw new PersistenceException( "Error loading all the references, check log for more details."); } return index; }
private void saveIndex(XMLMemento memento) { for (Entry<IPath, Set<IIndexedJavaRef>> fileEntry : fileIndex.entrySet()) { for (IIndexedJavaRef ref : fileEntry.getValue()) { IMemento refNode = memento.createChild(TAG_JAVA_REF); /* * Embed the Java reference class name into the index. This ends up * making the resulting index file larger than it really needs to be * (around 100 KB for the index containing gwt-user, gwt-lang, and all * the gwt-dev projects), but it still loads in around 50 ms on average * on my system, so it doesn't seem to be a bottleneck. */ String refClassName = ref.getClass().getName(); refNode.putString(TAG_JAVA_REF_CLASS, refClassName); // The implementation of IIndexedJavaRef serializes itself ref.save(refNode); } } }
public static UiXmlReferencedFieldIndex load(IMemento memento) throws PersistenceException { UiXmlReferencedFieldIndex index = new UiXmlReferencedFieldIndex(); boolean hadException = false; for (IMemento childMemento : memento.getChildren(KEY_UI_FIELD_REF)) { try { loadFieldRef(childMemento, index); } catch (PersistenceException e) { CorePluginLog.logError(e, "Error loading persisted index entry."); hadException = true; } } if (hadException) { throw new PersistenceException( "Error loading all the references, check log for more details."); } return index; }
private static IReferenceLocation loadReferenceLocation(IMemento memento) throws PersistenceException { String className = getStringOrThrowException(memento, KEY_CLASS); if (ClasspathRelativeFileReferenceLocation.class.getSimpleName().equals( className)) { String classpathRelativePath = getStringOrThrowException(memento, KEY_CLASSPATH_RELATIVE_PATH); return new ClasspathRelativeFileReferenceLocation( Path.fromPortableString(classpathRelativePath)); } else if (LogicalJavaElementReferenceLocation.class.getSimpleName().equals( className)) { ILogicalJavaElement logicalJavaElement = loadLogicalJavaElement(getChildMementoOrThrowException( memento, KEY_LOGICAL_JAVA_ELEMENT)); return new LogicalJavaElementReferenceLocation(logicalJavaElement); } else { throw new PersistenceException("Unknown reference location class " + className); } }
private static Set<IReference> loadReferences(IMemento memento) throws PersistenceException { Set<IReference> references = new HashSet<IReference>(); boolean hadException = false; for (IMemento childMemento : memento.getChildren(KEY_REFERENCE)) { try { IReference loadedReference = loadReference(childMemento); if (loadedReference != null) { references.add(loadedReference); } } catch (PersistenceException e) { CorePluginLog.logError(e, "Error loading persisted reference."); hadException = true; } } if (hadException) { throw new PersistenceException( "Error loading all the references, check log for more details."); } return references; }
private static void persistLogicalJavaElement(ILogicalJavaElement element, IMemento memento) throws PersistenceException { memento.putString(KEY_CLASS, element.getClass().getSimpleName()); if (element instanceof LogicalType) { memento.putString(KEY_FULLY_QUALIFIED_NAME, ((LogicalType) element).getFullyQualifiedName()); } else if (element instanceof LogicalPackage) { memento.putString(KEY_PACKAGE_NAME, ((LogicalPackage) element).getPackageName()); } else { throw new PersistenceException("Could not persist " + element.getClass().getName()); } }
@Override protected void storeItemToMemento(final Object item, final IMemento memento) { if (item instanceof IEObjectDescription) { final URI uri = ((IEObjectDescription) item).getEObjectURI(); memento.putString(MEMENTO_URI_KEY, uri.toString()); } }