org.eclipse.ui.IMemento Java Examples

The following examples show how to use org.eclipse.ui.IMemento. 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: JavaNavigatorViewActionProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void restoreState(IMemento memento) {
	boolean isCurrentLayoutFlat= true;
	Integer state= null;
	if (memento != null)
		state= memento.getInteger(TAG_LAYOUT);

	// If no memento try an restore from preference store
	if (state == null) {
		IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore();
		state= new Integer(store.getInt(TAG_LAYOUT));
	}

	if (state.intValue() == FLAT_LAYOUT)
		isCurrentLayoutFlat= true;
	else
		if (state.intValue() == HIERARCHICAL_LAYOUT)
			isCurrentLayoutFlat= false;

	fStateModel.setBooleanProperty(Values.IS_LAYOUT_FLAT, isCurrentLayoutFlat);
	fLayoutActionGroup.setFlatLayout(isCurrentLayoutFlat);
}
 
Example #2
Source File: JavaRefIndex.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
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);
    }
  }
}
 
Example #3
Source File: JavaNavigatorContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void init(ICommonContentExtensionSite commonContentExtensionSite) {
	IExtensionStateModel stateModel = commonContentExtensionSite
			.getExtensionStateModel();
	IMemento memento = commonContentExtensionSite.getMemento();

	fStateModel = stateModel;
	restoreState(memento);
	fLayoutPropertyListener = new IPropertyChangeListener() {
		public void propertyChange(PropertyChangeEvent event) {
			if (Values.IS_LAYOUT_FLAT.equals(event.getProperty())) {
				if (event.getNewValue() != null) {
					boolean newValue = ((Boolean) event.getNewValue())
							.booleanValue() ? true : false;
					setIsFlatLayout(newValue);
				}
			}

		}
	};
	fStateModel.addPropertyChangeListener(fLayoutPropertyListener);

	IPreferenceStore store = PreferenceConstants.getPreferenceStore();
	boolean showCUChildren = store
			.getBoolean(PreferenceConstants.SHOW_CU_CHILDREN);
	setProvideMembers(showCUChildren);
}
 
Example #4
Source File: GamaNavigator.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void saveState(final IMemento newMemento) {
	if (GamaPreferences.Interface.KEEP_NAVIGATOR_STATE.getValue()) {
		final StringBuilder sb = new StringBuilder();
		for (final Object o : getCommonViewer().getExpandedElements()) {
			final String name =
					o instanceof WrappedContainer ? ((WrappedContainer<?>) o).getResource().getFullPath().toString()
							: o instanceof TopLevelFolder ? ((TopLevelFolder) o).getName() : null;
			if (name != null) {
				sb.append(name);
				sb.append("@@");
			}
		}
		if (sb.length() > 2) {
			sb.setLength(sb.length() - 2);
		}
		newMemento.putString("EXPANDED_STATE", sb.toString());
	}
	super.saveState(newMemento);
}
 
Example #5
Source File: ReferenceManagerPersister.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private static IReference loadReference(IMemento memento)
    throws PersistenceException {
  String projectName = getStringOrThrowException(memento, KEY_SOURCE_PROJECT);
  IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
  if (project == null || !project.exists()) {
    // This is not an exception, since the reference is no longer needed if
    // its originating point does not exist
    CorePluginLog.logWarning(MessageFormat.format(
        "Not loading reference since the source project {0} does not exist anymore.",
        projectName));
    return null;
  }
  
  IReferenceLocation sourceLocation = loadReferenceLocation(getChildMementoOrThrowException(
      memento, KEY_SOURCE_LOCATION));
  IReferenceLocation targetLocation = loadReferenceLocation(getChildMementoOrThrowException(
      memento, KEY_TARGET_LOCATION));

  return new Reference(sourceLocation, targetLocation, project);
}
 
Example #6
Source File: UiXmlReferencedFieldIndex.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example #7
Source File: PyEditorInputFactory.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public IAdaptable createElement(IMemento memento) {
    String fileStr = memento.getString(TAG_FILE);
    if (fileStr == null || fileStr.length() == 0) {
        return null;
    }

    String zipPath = memento.getString(TAG_ZIP_PATH);
    final File file = new File(fileStr);
    if (zipPath == null || zipPath.length() == 0) {
        //return EditorInputFactory.create(new File(file), false);
        final URI uri = file.toURI();
        IFile[] ret = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(uri,
                IContainer.INCLUDE_HIDDEN | IContainer.INCLUDE_PHANTOMS | IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
        if (ret != null && ret.length > 0) {
            return new FileEditorInput(ret[0]);
        }
        try {
            return new FileStoreEditorInput(EFS.getStore(uri));
        } catch (CoreException e) {
            return new PydevFileEditorInput(file);
        }
    }

    return new PydevZipFileEditorInput(new PydevZipFileStorage(file, zipPath));
}
 
Example #8
Source File: SQLBuilderDesignState.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a SQB designer state from a previously saved ODA DesignerState.
 * @param odaDesignerState
 * @throws OdaException
 */
SQLBuilderDesignState( final DesignerState odaDesignerState ) throws OdaException
{
    if( odaDesignerState == null || odaDesignerState.getStateContent() == null )
        throw new NullPointerException( "SQLBuilderDesignState( DesignerState )" ); //$NON-NLS-1$

    // check the version compatibility of designerState
    m_version = odaDesignerState.getVersion();
    if( m_version == null || 
        ! m_version.equals( SQB_STATE_CURRENT_VERSION ) ) // currently supports a single version only
    {
        throw new OdaException( Messages.sqbDesignState_invalidSqbStateVersion );
    }
    
    // get the designer state content
    String designStateValue = odaDesignerState.getStateContent().getStateContentAsString();
    if( designStateValue == null )
        return;     // no state content

    IMemento memento = SQLBuilderEditorInputUtil.readMementoFromString( designStateValue );

    DesignStateMemento.restoreState( memento, this );
}
 
Example #9
Source File: MemberFilterActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 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) {
	setMemberFilters(
		new int[] {FILTER_FIELDS, FILTER_STATIC, FILTER_NONPUBLIC, FILTER_LOCALTYPES},
		new boolean[] {
			Boolean.valueOf(memento.getString(TAG_HIDEFIELDS)).booleanValue(),
			Boolean.valueOf(memento.getString(TAG_HIDESTATIC)).booleanValue(),
			Boolean.valueOf(memento.getString(TAG_HIDENONPUBLIC)).booleanValue(),
			Boolean.valueOf(memento.getString(TAG_HIDELOCALTYPES)).booleanValue()
		}, false);
}
 
Example #10
Source File: ApplicationOverviewEditorInputFactory.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public static void saveState(IMemento memento, ApplicationOverviewEditorInput input) {
	if (input == null) {
		return;
	}
	
	if (input.connectionId != null) {
		memento.putString(CONNECTION_ID, input.connectionId);
	}
	memento.putString(CONNECTION_URI, input.connectionUri);
	if (input.connectionName != null) {
		memento.putString(CONNECTION_NAME, input.connectionName);
	}
	memento.putString(PROJECT_ID, input.projectID);
	memento.putString(PROJECT_NAME, input.projectName);
}
 
Example #11
Source File: ClassFileEditorInputFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public IAdaptable createElement(IMemento memento) {
	String identifier= memento.getString(KEY);
	if (identifier == null)
		return null;

	IJavaElement element= JavaCore.create(identifier);
	try {
		if (!element.exists() && element instanceof IClassFile) {
			/*
			 * Let's try to find the class file,
			 * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=83221
			 */
			IClassFile cf= (IClassFile)element;
			IType type= cf.getType();
			IJavaProject project= element.getJavaProject();
			if (project != null) {
				type= project.findType(type.getFullyQualifiedName());
				if (type == null)
					return null;
				element= type.getParent();
			}
		}
		return EditorUtility.getEditorInput(element);
	} catch (JavaModelException x) {
		// Don't report but simply return null
		return null;
	}
}
 
Example #12
Source File: InputURLDialog.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected IMemento getMemento() {
	File file = UIEplPlugin.getDefault().getStateLocation().append(URLS).addFileExtension(XML).toFile();
	if (file.exists()) {
		try {
			FileReader reader = new FileReader(file);
			XMLMemento memento = XMLMemento.createReadRoot(reader);
			return memento;
		} catch (Exception e) {
			IdeLog.logError(UIEplPlugin.getDefault(), e);
		}
	}
	return null;
}
 
Example #13
Source File: ControlView.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void saveState(IMemento memento) {
    int i = 0;
    for (ITraceControlComponent cmp : fRoot.getChildren()) {
        if (cmp instanceof TargetNodeComponent) {
            IRemoteConnection rc = ((TargetNodeComponent) cmp).getRemoteSystemProxy().getRemoteConnection();
            memento.putString(KEY_REMOTE_PROVIDER + i, rc.getConnectionType().getId());
            memento.putString(KEY_REMOTE_CONNECTION_NAME + i, rc.getName());
            i++;
        }
    }
    super.saveState(memento);
}
 
Example #14
Source File: XbaseEditor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void doRestoreState(IMemento memento) {
	super.doRestoreState(memento);
	String handleIdentifier = memento.getString(HANDLER_IDENTIFIER);
	if (handleIdentifier != null) {
		IJavaElement handle = JavaCore.create(handleIdentifier);
		if (handle instanceof ITypeRoot && handle.exists()) {
			typeRoot = (ITypeRoot) handle;
		}
	}
}
 
Example #15
Source File: MembersView.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void restoreState(IMemento memento) {
	super.restoreState(memento);
	fMemberFilterActionGroup.restoreState(memento);
	getViewer().getControl().setRedraw(false);
	getViewer().refresh();
		getViewer().getControl().setRedraw(true);
}
 
Example #16
Source File: KonsDetailView.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void saveState(IMemento memento){
	int[] w = sash.getWeights();
	memento.putString(CFG_VERTRELATION,
		Integer.toString(w[0]) + StringConstants.COMMA + Integer.toString(w[1]));
	
	w = diagAndChargeSash.getWeights();
	memento.putString(CFG_HORIZRELATION,
		Integer.toString(w[0]) + StringConstants.COMMA + Integer.toString(w[1]));
	
	super.saveState(memento);
}
 
Example #17
Source File: CustomDrawerEditPart.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#saveState(org.eclipse.ui.IMemento)
 */
public void saveState(IMemento memento) {
	RangeModel rModel = getDrawerFigure().getScrollpane().getViewport()
			.getVerticalRangeModel();
	memento.putInteger(RangeModel.PROPERTY_MINIMUM, rModel.getMinimum());
	memento.putInteger(RangeModel.PROPERTY_MAXIMUM, rModel.getMaximum());
	memento.putInteger(RangeModel.PROPERTY_EXTENT, rModel.getExtent());
	memento.putInteger(RangeModel.PROPERTY_VALUE, rModel.getValue());
	super.saveState(memento);
}
 
Example #18
Source File: WorkingSetFilterActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 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
 */
public void restoreState(IMemento memento) {
	String workingSetName= memento.getString(TAG_WORKING_SET_NAME);
	if (workingSetName != null && workingSetName.length() > 0) {
		setWorkingSet(PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSet(workingSetName), false);
	} else if (fWorkbenchPage != null && useWindowWorkingSetByDefault()) {
		setWorkingSet(fWorkbenchPage.getAggregateWorkingSet(), false);
	}
}
 
Example #19
Source File: InputURLDialog.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private final void loadList() {
	IMemento memento = getMemento();
	if (memento == null) {
		return;
	}
	IMemento[] list = memento.getChildren(URL);
	for(int i = 0; i < list.length; ++i) {
		combo.add(list[i].getTextData());
	}
}
 
Example #20
Source File: StatechartDefinitionSection.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void restoreState(IMemento memento) {
	if (getSash() != null && memento != null) {
		Boolean hasMemento = getExpandProperty(memento);
		if (hasMemento != null) {
			previousWidths = getWeightProperties(memento);
			sectionExpanded = hasMemento.booleanValue();
			refreshEditorContents();
			saveCurrentMemento(memento);
		} else {
			saveState(memento);
		}
		getSash().setWeights(previousWidths);
	}
}
 
Example #21
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 #22
Source File: ReferenceManager.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public static ReferenceManager load(IMemento memento)
    throws PersistenceException {
  ReferenceManager referenceManager = new ReferenceManager();
  for (IReference reference : ReferenceManagerPersister.load(memento)) {
    referenceManager.addReference(reference);
  }
  return referenceManager;
}
 
Example #23
Source File: FilteredTypesSelectionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void restoreDialog(IDialogSettings settings) {
	super.restoreDialog(settings);

	if (! BUG_184693) {
		boolean showContainer= settings.getBoolean(SHOW_CONTAINER_FOR_DUPLICATES);
		fShowContainerForDuplicatesAction.setChecked(showContainer);
		fTypeInfoLabelProvider.setContainerInfo(showContainer);
	} else {
		fTypeInfoLabelProvider.setContainerInfo(true);
	}

	if (fAllowScopeSwitching) {
		String setting= settings.get(WORKINGS_SET_SETTINGS);
		if (setting != null) {
			try {
				IMemento memento= XMLMemento.createReadRoot(new StringReader(setting));
				fFilterActionGroup.restoreState(memento);
			} catch (WorkbenchException e) {
				// don't do anything. Simply don't restore the settings
				JavaPlugin.log(e);
			}
		}
		IWorkingSet ws= fFilterActionGroup.getWorkingSet();
		if (ws == null || (ws.isAggregateWorkingSet() && ws.isEmpty())) {
			setSearchScope(SearchEngine.createWorkspaceScope());
			setSubtitle(null);
		} else {
			setSearchScope(JavaSearchScopeFactory.getInstance().createJavaSearchScope(ws, true));
			setSubtitle(ws.getLabel());
		}
	}

	// TypeNameMatch[] types = OpenTypeHistory.getInstance().getTypeInfos();
	//
	// for (int i = 0; i < types.length; i++) {
	// TypeNameMatch type = types[i];
	// accessedHistoryItem(type);
	// }
}
 
Example #24
Source File: CustomDrawerEditPart.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#restoreState(org.eclipse.ui.IMemento)
 */
public void restoreState(IMemento memento) {
	RangeModel rModel = getDrawerFigure().getScrollpane().getViewport()
			.getVerticalRangeModel();
	rModel.setMinimum(memento.getInteger(RangeModel.PROPERTY_MINIMUM)
			.intValue());
	rModel.setMaximum(memento.getInteger(RangeModel.PROPERTY_MAXIMUM)
			.intValue());
	rModel.setExtent(memento.getInteger(RangeModel.PROPERTY_EXTENT)
			.intValue());
	rModel.setValue(memento.getInteger(RangeModel.PROPERTY_VALUE)
			.intValue());
	super.restoreState(memento);
}
 
Example #25
Source File: DetailsViewPart.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void saveState ( final IMemento memento )
{
    if ( this.initItem != null )
    {
        super.saveState ( memento );
        this.initItem.saveTo ( memento );
    }
}
 
Example #26
Source File: MonitorsView.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 )
    {
        final String s = memento.getString ( "columnSettings" ); //$NON-NLS-1$
        if ( s != null )
        {
            this.initialColumnSettings = this.gson.fromJson ( s, new TypeToken<List<ColumnProperties>> () {}.getType () );
        }
    }
}
 
Example #27
Source File: ReferenceManager.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public void persist(IMemento memento) {
  HashSet<IReference> copiedReferences;

  synchronized (references) {
    copiedReferences = new HashSet<IReference>(references);
  }

  ReferenceManagerPersister.persist(copiedReferences, memento);
}
 
Example #28
Source File: SwitchPaletteMode.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public void save() {
	if (paletteStates.isEmpty()) {
		return;
	}

	// If there are already existing palette customizations we will add to
	// them, otherwise, create a new XML memento which makes it easy to save
	// the customizations in a tree format.
	XMLMemento rootMemento = getExistingCustomizations();
	if (rootMemento == null) {
		rootMemento = XMLMemento.createWriteRoot(PALETTE_CUSTOMIZATIONS_ID);
	}
	for (Iterator<Entry<PaletteEntry, IPaletteState>> iterator = paletteStates.entrySet().iterator(); iterator.hasNext();) {
		Entry<PaletteEntry, IPaletteState> entry = iterator.next();
		IMemento memento = getMementoForEntry(rootMemento, entry.getKey());
		if (memento != null) {
			entry.getValue().storeChangesInMemento(memento);
		}
	}

	StringWriter writer = new StringWriter();
	try {
		rootMemento.save(writer);

		if (preferences != null) {
			preferences.setValue(PALETTE_CUSTOMIZATIONS_ID, writer.toString());
		}
	} catch (IOException e) {
		Trace.catching(GefPlugin.getInstance(), GefDebugOptions.EXCEPTIONS_CATCHING, getClass(),
				"Problem saving the XML memento when saving the palette customizations.", //$NON-NLS-1$
				e);
		Log.warning(GefPlugin.getInstance(), GefStatusCodes.IGNORED_EXCEPTION_WARNING,
				"Problem saving the XML memento when saving the palette customizations.", //$NON-NLS-1$
				e);
	}

	paletteStates.clear();
}
 
Example #29
Source File: JavaBrowsingPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void saveState(IMemento memento) {
	if (fViewer == null) {
		// part has not been created
		if (fMemento != null) //Keep the old state;
			memento.putMemento(fMemento);
		return;
	}
	if (fHasWorkingSetFilter)
		fWorkingSetFilterActionGroup.saveState(memento);
	if (fHasCustomFilter)
		fCustomFiltersActionGroup.saveState(memento);
	saveSelectionState(memento);
	saveLinkingEnabled(memento);
}
 
Example #30
Source File: ReferenceManagerPersister.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private static String getStringOrThrowException(IMemento memento, String key)
    throws PersistenceException {
  String string = memento.getString(key);
  if (string == null) {
    throw new PersistenceException("Could not get string for key " + key);
  }
  return string;
}