Java Code Examples for org.eclipse.ui.IMemento#createChild()

The following examples show how to use org.eclipse.ui.IMemento#createChild() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RealTimeListViewer.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
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$
    }
}
 
Example 2
Source File: JavaBrowsingPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void saveSelectionState(IMemento memento) {
	Object elements[]= ((IStructuredSelection) fViewer.getSelection()).toArray();
	if (elements.length > 0) {
		IMemento selectionMem= memento.createChild(TAG_SELECTED_ELEMENTS);
		for (int i= 0; i < elements.length; i++) {
			IMemento elementMem= selectionMem.createChild(TAG_SELECTED_ELEMENT);
			Object o= elements[i];
			if (o instanceof IJavaElement)
				elementMem.putString(TAG_SELECTED_ELEMENT_PATH, ((IJavaElement) elements[i]).getHandleIdentifier());
			else if (o instanceof LogicalPackage) {
				IPackageFragment[] packages=((LogicalPackage)o).getFragments();
				for (int j= 0; j < packages.length; j++) {
					IMemento packageMem= elementMem.createChild(TAG_LOGICAL_PACKAGE);
					packageMem.putString(TAG_SELECTED_ELEMENT_PATH, packages[j].getHandleIdentifier());
				}
			}
		}
	}
}
 
Example 3
Source File: ChartView.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void saveState ( final IMemento memento )
{
    super.saveState ( memento );
    if ( memento == null )
    {
        return;
    }

    final Resource resource = new XMIResourceFactoryImpl ().createResource ( null );
    resource.getContents ().add ( this.configuration );

    final ByteArrayOutputStream outputStream = new ByteArrayOutputStream ();

    final Map<?, ?> options = new HashMap<Object, Object> ();

    try
    {
        resource.save ( outputStream, options );
        final IMemento child = memento.createChild ( CHILD_CONFIGURATION );

        child.putTextData ( StringUtils.newStringUtf8 ( Base64.encodeBase64 ( outputStream.toByteArray (), true ) ) );
    }
    catch ( final Exception e )
    {
        StatusManager.getManager ().handle ( StatusHelper.convertStatus ( Activator.PLUGIN_ID, e ), StatusManager.LOG );
    }
}
 
Example 4
Source File: SdkManager.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
private void saveSdkRegistry(XMLMemento memento, SdkRegistry sdkRegistry) {
       String actSdk = (sdkRegistry.getDefaultSdk() != null) ? sdkRegistry.getDefaultSdk().getName() : ""; //$NON-NLS-1$
       IPreferenceStore store = XdsCorePlugin.getDefault().getPreferenceStore();
       store.setValue(KEY_ACTIVE_SDK_NAME, actSdk);
       WorkspacePreferencesManager.getInstance().flush();

	for (Sdk sdk : sdkRegistry.getRegisteredSDKs()) {
		IMemento mementoSdk = memento.createChild(TAG_SDK);
		for (Sdk.Property property: Sdk.Property.values()) {
			mementoSdk.putString(property.xmlKey, sdk.getPropertyValue(property));
			for (Sdk.Tag tag : property.possibleTags) {
			    String val = sdk.getTag(property, tag);
			    if (val != null) {
			        String key = property.xmlKey + "_" + tag.xmlTagName; //$NON-NLS-1$
	                mementoSdk.putString(key, val);
			    }
			}
		}
		 Map<String, String> environmentVariables = sdk.getEnvironmentVariablesRaw();
		if (!environmentVariables.isEmpty()) {
			for (Map.Entry<String, String> entry : environmentVariables.entrySet()) {
				IMemento mementoEnvVar = mementoSdk.createChild(TAG_ENVIRONMENT_VARIABLE);
				mementoEnvVar.putString(TAG_ENVIRONMENT_VARIABLE_NAME,  entry.getKey());
				mementoEnvVar.putString(TAG_ENVIRONMENT_VARIABLE_VALUE, entry.getValue());
			}
		}
		saveTools(mementoSdk, sdk);
	}
}
 
Example 5
Source File: SdkManager.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
private static void saveTools(IMemento memento, Sdk sdk) {
	List<SdkTool> tools = sdk.getTools();
	IMemento toolsMemento = memento.createChild(TAG_TOOL_COLLECTION);
	for (SdkTool tool : tools) {
		IMemento toolMemento = toolsMemento.createChild(TAG_TOOL);
		if (tool.isSeparator()) {
               toolMemento.putBoolean("isSeprator", true); //$NON-NLS-1$
               toolMemento.putString(SdkTool.Property.MENU_GROUP.tag, tool.getPropertyValue(SdkTool.Property.MENU_GROUP));
		} else {
               for (SdkTool.Property property: SdkTool.Property.values()) {
                   toolMemento.putString(property.tag, tool.getPropertyValue(property));
               }
		}
	}
}
 
Example 6
Source File: FilteredItemsSelectionDialog.java    From tlaplus with MIT License 5 votes vote down vote up
/**
 * Save history elements to memento.
 *
 * @param memento
 *            memento to which the history will be added
 */
public void save(IMemento memento) {

	IMemento historyMemento = memento.createChild(rootNodeName);

	Object[] items = getHistoryItems();
	for (int i = 0; i < items.length; i++) {
		Object item = items[i];
		IMemento elementMemento = historyMemento
				.createChild(infoNodeName);
		storeItemToMemento(item, elementMemento);
	}

}
 
Example 7
Source File: CompilationUnitResourceDependencyIndex.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private void persistIndex(XMLMemento memento) {
  for (ICompilationUnit cu : index.getAllLeftElements()) {
    IMemento cuNode = memento.createChild(TAG_DEPENDENCIES);
    cuNode.putString(ATTR_COMPILATION_UNIT, cu.getHandleIdentifier());

    for (IPath resourcePath : index.getRightElements(cu)) {
      IMemento resNode = cuNode.createChild(TAG_RESOURCE);
      resNode.putString(ATTR_RESOURCE_PATH, resourcePath.toString());
    }
  }
}
 
Example 8
Source File: InputURLDialog.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected final void saveList(IMemento memento) {
	String firstItem = combo.getText();
	IMemento child = memento.createChild(URL);
	child.putTextData(firstItem);
	
	String[] list = combo.getItems();
	for(int i = 0; i < list.length; ++i) {
		if (list[i].equals(firstItem)) {
			continue;
		}
		child = memento.createChild(URL);
		child.putTextData(list[i]);
	}
}
 
Example 9
Source File: CustomFiltersActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Saves the state of the custom filters in a memento.
 *
 * @param memento the memento into which the state is saved
 */
public void saveState(IMemento memento) {
	IMemento customFilters= memento.createChild(TAG_CUSTOM_FILTERS);
	customFilters.putString(TAG_USER_DEFINED_PATTERNS_ENABLED, Boolean.toString(fUserDefinedPatternsEnabled));
	saveUserDefinedPatterns(customFilters);
	saveXmlDefinedFilters(customFilters);
	saveLRUFilters(customFilters);
}
 
Example 10
Source File: CustomFiltersActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void saveXmlDefinedFilters(IMemento memento) {
	IMemento xmlDefinedFilters= memento.createChild(TAG_XML_DEFINED_FILTERS);

	for (Iterator<FilterItem> iterator= fFilterItems.values().iterator(); iterator.hasNext();) {
		FilterItem item= iterator.next();

		IMemento child= xmlDefinedFilters.createChild(TAG_CHILD);
		child.putString(TAG_FILTER_ID, item.id);
		child.putString(TAG_IS_ENABLED, String.valueOf(item.enabled));
	}
}
 
Example 11
Source File: CustomFiltersActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Stores the last recently used filter Ids into
 * the given memento
 *
 * @param memento the memento into which to store the LRU filter Ids
 * @since 3.0
 */
private void saveLRUFilters(IMemento memento) {
	if(fLRUFilterIdsStack != null && !fLRUFilterIdsStack.isEmpty()) {
		IMemento lruFilters= memento.createChild(TAG_LRU_FILTERS);
		Iterator<String> iter= fLRUFilterIdsStack.iterator();
		while (iter.hasNext()) {
			String id= iter.next();
			IMemento child= lruFilters.createChild(TAG_CHILD);
			child.putString(TAG_FILTER_ID, id);
		}
	}
}
 
Example 12
Source File: CustomFiltersActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void saveUserDefinedPatterns(IMemento memento) {
	if(fUserDefinedPatterns != null && fUserDefinedPatterns.length > 0) {
		IMemento userDefinedPatterns= memento.createChild(TAG_USER_DEFINED_PATTERNS);
		for (int i= 0; i < fUserDefinedPatterns.length; i++) {
			IMemento child= userDefinedPatterns.createChild(TAG_CHILD);
			child.putString(TAG_PATTERN, fUserDefinedPatterns[i]);
		}
	}
}
 
Example 13
Source File: TmxEditorHistory.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Save the most-recently-used history in the history file
 */
public IStatus saveState(IMemento memento) {
	Iterator<TmxEditorHistoryItem> iterator = fifoList.iterator();
	while (iterator.hasNext()) {
		TmxEditorHistoryItem item = iterator.next();
		if (item.canSave()) {
			IMemento itemMemento = memento.createChild(rootTag);
			item.saveState(itemMemento);
		}
	}
	return Status.OK_STATUS;
}
 
Example 14
Source File: SwitchPaletteMode.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Given the rootMemento, gets the memento that already exists for the
 * palette entry or creates a new one in the rootMemento (and the necessary
 * palette container mementos) if one does not exist yet. The root memento's
 * tree structure matches that of the palette root. If a palette entry in
 * stack A, in drawer B is customized, the root memento will have a child
 * memento for drawer B which has a child memento for stack A which has a
 * child memento for the entry. The memento's use the palette entry's id.
 * 
 * @param rootMemento
 *            the root memento representing the palette root
 * @param paletteEntry
 *            the palette entry for which a memento should be retrieved or
 *            created
 * @return returns the memento that already exists for the palette entry or
 *         creates a new one in the rootMemento if one does not exist yet or
 *         null if the memento could not be created (most likely because the
 *         palete id is not acceptable).
 */
private IMemento getMementoForEntry(IMemento rootMemento, PaletteEntry paletteEntry) {

	ArrayList<String> idList = new ArrayList<String>();
	idList.add(paletteEntry.getId());

	PaletteContainer parent = paletteEntry.getParent();
	while (parent != null && !PaletteRoot.PALETTE_TYPE_ROOT.equals(parent.getType())) {
		idList.add(parent.getId());
		parent = parent.getParent();
	}

	// go through ids in reverse order and create the mementos as necessary
	IMemento containerMemento = rootMemento;
	for (int i = idList.size() - 1; i >= 0; i--) {
		String id = idList.get(i);
		IMemento memento = containerMemento.getChild(id);
		if (memento == null) {
			try {
				memento = containerMemento.createChild(id);
			} catch (Exception e) {
				Trace.catching(GefPlugin.getInstance(), GefDebugOptions.EXCEPTIONS_CATCHING, getClass(),
						"Invalid palette id encountered when saving the palette customizations.", //$NON-NLS-1$
						e);
				Log.warning(GefPlugin.getInstance(), GefStatusCodes.IGNORED_EXCEPTION_WARNING,
						"Invalid palette id encountered when saving the palette customizations.", //$NON-NLS-1$
						e);
				return null;
			}
		}
		containerMemento = memento;
	}

	return containerMemento;
}