下面列出了org.eclipse.ui.IMemento#getChild ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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);
}
}
}
/**
* 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();
}
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;
}
@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 );
}
}
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 ) );
}
}
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;
}
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]);
}
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();
}
}
}
}
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);
}
}
}
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;
}
/**
* 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;
}