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

The following examples show how to use org.eclipse.ui.IMemento#getChild() . 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: FilteredItemsSelectionDialog.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * 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);
		}
	}
}
 
Example 2
Source File: CustomFiltersActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Restores the state of the filter actions from a memento.
 * <p>
 * Note: This method does not refresh the viewer.
 * </p>
 *
 * @param memento the memento from which the state is restored
 */
public void restoreState(IMemento memento) {
	if (memento == null)
		return;
	IMemento customFilters= memento.getChild(TAG_CUSTOM_FILTERS);
	if (customFilters == null)
		return;
	String userDefinedPatternsEnabled= customFilters.getString(TAG_USER_DEFINED_PATTERNS_ENABLED);
	if (userDefinedPatternsEnabled == null)
		return;

	fUserDefinedPatternsEnabled= Boolean.valueOf(userDefinedPatternsEnabled).booleanValue();
	restoreUserDefinedPatterns(customFilters);
	restoreXmlDefinedFilters(customFilters);
	restoreLRUFilters(customFilters);

	updateViewerFilters();
}
 
Example 3
Source File: CheckFileOnOpenPartListener.java    From eclipse-cs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private IEditorInput getRestoredInput(IEditorReference e) {

    IMemento editorMem = null;
    if (CheckstyleUIPlugin.isE3()) {
      editorMem = getMementoE3(e);
    } else {
      editorMem = getMementoE4(e);
    }

    if (editorMem == null) {
      return null;
    }
    IMemento inputMem = editorMem.getChild(IWorkbenchConstants.TAG_INPUT);
    String factoryID = null;
    if (inputMem != null) {
      factoryID = inputMem.getString(IWorkbenchConstants.TAG_FACTORY_ID);
    }
    if (factoryID == null) {
      return null;
    }
    IAdaptable input = null;

    IElementFactory factory = PlatformUI.getWorkbench().getElementFactory(factoryID);
    if (factory == null) {
      return null;
    }

    input = factory.createElement(inputMem);
    if (input == null) {
      return null;
    }

    if (!(input instanceof IEditorInput)) {
      return null;
    }
    return (IEditorInput) input;
  }
 
Example 4
Source File: ChartView.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void init ( final IViewSite site, final IMemento memento ) throws PartInitException
{
    super.init ( site, memento );

    if ( memento == null )
    {
        return;
    }

    final IMemento child = memento.getChild ( CHILD_CONFIGURATION );
    if ( child == null )
    {
        return;
    }

    final String data = child.getTextData ();
    if ( data == null || data.isEmpty () )
    {
        return;
    }

    try
    {
        this.configuration = load ( new ByteArrayInputStream ( Base64.decodeBase64 ( data ) ) );
    }
    catch ( final Exception e )
    {
        StatusManager.getManager ().handle ( StatusHelper.convertStatus ( Activator.PLUGIN_ID, e ), StatusManager.LOG );
    }
}
 
Example 5
Source File: RealTimeListViewer.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public void loadFrom ( final IMemento memento )
{
    if ( memento == null )
    {
        return;
    }

    try
    {
        {
            this.initialColWidth = new LinkedList<Integer> ();
            final IMemento tableMemento = memento.getChild ( "tableCols" ); //$NON-NLS-1$
            if ( tableMemento != null )
            {
                int i = 0;
                Integer w;
                while ( ( w = tableMemento.getInteger ( "col_" + i ) ) != null ) //$NON-NLS-1$
                {
                    this.initialColWidth.add ( w );
                    i++;
                }
            }
        }

        for ( final IMemento child : memento.getChildren ( "item" ) ) //$NON-NLS-1$
        {
            final Item item = Item.loadFrom ( child );
            if ( item != null )
            {
                this.list.add ( item );
            }
        }
    }
    catch ( final Exception e )
    {
        Activator.getDefault ().getLog ().log ( new Status ( IStatus.ERROR, Activator.PLUGIN_ID, Messages.RealTimeListViewer_ErrorLoadingData, e ) );
    }
}
 
Example 6
Source File: ReferenceManagerPersister.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private static IMemento getChildMementoOrThrowException(
    IMemento parentMemento, String childMementoType)
    throws PersistenceException {
  IMemento childMemento = parentMemento.getChild(childMementoType);
  if (childMemento == null) {
    throw new PersistenceException("There is no child memento with type "
        + childMementoType);
  }

  return childMemento;
}
 
Example 7
Source File: CustomFiltersActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void restoreUserDefinedPatterns(IMemento memento) {
	IMemento userDefinedPatterns= memento.getChild(TAG_USER_DEFINED_PATTERNS);
	if(userDefinedPatterns != null) {
		IMemento children[]= userDefinedPatterns.getChildren(TAG_CHILD);
		String[] patterns= new String[children.length];
		for (int i = 0; i < children.length; i++)
			patterns[i]= children[i].getString(TAG_PATTERN);

		setUserDefinedPatterns(patterns);
	} else
		setUserDefinedPatterns(new String[0]);
}
 
Example 8
Source File: CustomFiltersActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void restoreXmlDefinedFilters(IMemento memento) {
	IMemento xmlDefinedFilters= memento.getChild(TAG_XML_DEFINED_FILTERS);
	if(xmlDefinedFilters != null) {
		IMemento[] children= xmlDefinedFilters.getChildren(TAG_CHILD);
		for (int i= 0; i < children.length; i++) {
			String id= children[i].getString(TAG_FILTER_ID);
			Boolean isEnabled= Boolean.valueOf(children[i].getString(TAG_IS_ENABLED));
			FilterItem item= fFilterItems.get(id);
			if (item != null) {
				item.enabled= isEnabled.booleanValue();
			}
		}
	}
}
 
Example 9
Source File: CustomFiltersActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void restoreLRUFilters(IMemento memento) {
	IMemento lruFilters= memento.getChild(TAG_LRU_FILTERS);
	fLRUFilterIdsStack.clear();
	if(lruFilters != null) {
		IMemento[] children= lruFilters.getChildren(TAG_CHILD);
		for (int i= 0; i < children.length; i++) {
			String id= children[i].getString(TAG_FILTER_ID);
			if (fFilterItems.containsKey(id) && !fLRUFilterIdsStack.contains(id))
				fLRUFilterIdsStack.push(id);
		}
	}
}
 
Example 10
Source File: JavaBrowsingPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private ISelection restoreSelectionState(IMemento memento) {
	if (memento == null)
		return null;

	IMemento childMem;
	childMem= memento.getChild(TAG_SELECTED_ELEMENTS);
	if (childMem != null) {
		ArrayList<Object> list= new ArrayList<Object>();
		IMemento[] elementMem= childMem.getChildren(TAG_SELECTED_ELEMENT);
		for (int i= 0; i < elementMem.length; i++) {
			String javaElementHandle= elementMem[i].getString(TAG_SELECTED_ELEMENT_PATH);
			if (javaElementHandle == null) {
				// logical package
				IMemento[] packagesMem= elementMem[i].getChildren(TAG_LOGICAL_PACKAGE);
				LogicalPackage lp= null;
				for (int j= 0; j < packagesMem.length; j++) {
					javaElementHandle= packagesMem[j].getString(TAG_SELECTED_ELEMENT_PATH);
					Object pack= JavaCore.create(javaElementHandle);
					if (pack instanceof IPackageFragment && ((IPackageFragment)pack).exists()) {
						if (lp == null)
							lp= new LogicalPackage((IPackageFragment)pack);
						else
							lp.add((IPackageFragment)pack);
					}
				}
				if (lp != null)
					list.add(lp);
			} else {
				IJavaElement element= JavaCore.create(javaElementHandle);
				if (element != null && element.exists())
					list.add(element);
			}
		}
		return new StructuredSelection(list);
	}
	return null;
}
 
Example 11
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;
}