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

The following examples show how to use org.eclipse.ui.IMemento#getString() . 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: AbstractAlarmsEventsView.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@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;
    }
}
 
Example 2
Source File: ScriptEditorInputFactory.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public IAdaptable createElement( IMemento memento )
{
	String fileName = memento.getString( TAG_PATH );
	if ( fileName == null )
	{
		return null;
	}

	String id = memento.getString( TAG_ID );
	if ( id == null )
	{
		return null;
	}

	File file = new File( fileName );
	if ( file != null )
	{
		return new DebugJsInput( file, id );
	}
	else
	{
		return null;
	}
}
 
Example 3
Source File: JsniJavaRefParamType.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public static JsniJavaRefParamType load(IMemento memento) {
  // Extract the string representing the reference itself
  String refString = memento.getTextData();
  if (refString == null) {
    return null;
  }

  // Set the source property (the file containing the reference)
  String sourceString = memento.getString(TAG_SOURCE);
  if (sourceString == null) {
    return null;
  }

  // Set the offset property (the location within the containing file)
  Integer offset = memento.getInteger(TAG_OFFSET);
  if (offset == null) {
    return null;
  }

  // Parse the reference string into an actual JsniJavaRefParamType
  return JsniJavaRefParamType.parse(new Path(sourceString),
      offset.intValue(), refString);
}
 
Example 4
Source File: DiagramEditorInputFactory.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
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);
}
 
Example 5
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 6
Source File: XbaseEditor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected boolean containsSavedState(IMemento memento) {
	boolean result = super.containsSavedState(memento);
	if (!result) {
		return memento.getString(HANDLER_IDENTIFIER) != null;
	}
	return result;
}
 
Example 7
Source File: UiBinderSubtypeToUiXmlIndex.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private static void loadEntry(IMemento memento,
    UiBinderSubtypeToUiXmlIndex index) throws PersistenceException {
  String uiXmlPath = memento.getString(KEY_UI_XML_PATH);
  if (uiXmlPath == null) {
    throw new PersistenceException("Missing key " + KEY_UI_XML_PATH);
  }

  String uiBinderSubtypeKey = memento.getString(KEY_UIBINDER_SUBTYPE);
  if (uiBinderSubtypeKey == null) {
    throw new PersistenceException("Missing key " + KEY_UIBINDER_SUBTYPE);
  }

  IJavaElement javaElement = JavaCore.create(uiBinderSubtypeKey);
  if (javaElement == null) {
    throw new PersistenceException("Could not create Java element with key "
        + uiBinderSubtypeKey);
  }

  if (!(javaElement instanceof IType)) {
    throw new PersistenceException("Expecting "
        + javaElement.getElementName() + " to be a type");
  }

  if (!javaElement.getJavaProject().isOpen()) {
    return;
  }

  if (!JavaModelSearch.isValidElement(javaElement)) {
    throw new PersistenceException(
        ((IType) javaElement).getFullyQualifiedName()
            + " is not a valid Java type");
  }

  // Add the subtype + ui.xml pair to the index
  index.setUiXmlPath((IType) javaElement, new Path(uiXmlPath));
}
 
Example 8
Source File: Mementos.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static IAdaptable restoreItem(IMemento memento, String factoryTag) {
	if (memento == null)
		return null;
    String factoryID = memento.getString(factoryTag);
    if (factoryID == null) return null;
    IElementFactory factory = PlatformUI.getWorkbench().getElementFactory(factoryID);
    if (factory == null) return null;
    return factory.createElement(memento);
}
 
Example 9
Source File: UiBinderSubtypeToOwnerIndex.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return an object representing the persisted memento, or null if the
 *         memento is no longer valid
 * @throws PersistenceException
 */
public static UiBinderSubtypeAndOwner load(IMemento memento)
    throws PersistenceException {
  String ownerTypeName = memento.getString(KEY_OWNER_TYPE_NAME);
  if (ownerTypeName == null) {
    throw new PersistenceException("Missing key " + KEY_OWNER_TYPE_NAME);
  }

  String uiBinderSubtypeKey = memento.getString(KEY_UIBINDER_SUBTYPE);
  if (uiBinderSubtypeKey == null) {
    throw new PersistenceException("Missing key " + KEY_UIBINDER_SUBTYPE);
  }

  IJavaElement javaElement = JavaCore.create(uiBinderSubtypeKey);
  if (javaElement == null) {
    throw new PersistenceException("Could not create type "
        + uiBinderSubtypeKey);
  }

  if (!(javaElement instanceof IType)) {
    throw new PersistenceException("Expecting "
        + javaElement.getElementName() + " to be a type");
  }

  if (!javaElement.getJavaProject().isOpen()) {
    return null;
  }

  if (!JavaModelSearch.isValidElement(javaElement)) {
    throw new PersistenceException(
        ((IType) javaElement).getFullyQualifiedName()
        + " is not a valid Java type");
  }

  return new UiBinderSubtypeAndOwner((IType) javaElement, ownerTypeName);
}
 
Example 10
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;
}
 
Example 11
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 12
Source File: SQLBuilderDesignState.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
static void restoreState( final IMemento memento, SQLBuilderDesignState sqbState )
{
    sqbState.setSQBStorageInput( 
            SQLBuilderEditorInputUtil.createSQLBuilderStorageEditorInput( memento ) );

    String queryText = memento.getString( KEY_PREPARABLE_SQL_TEXT );
    sqbState.setPreparableSQL( queryText );     // could be null
}
 
Example 13
Source File: KonsDetailView.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void init(IViewSite site, IMemento memento) throws PartInitException{
	
	if (memento == null) {
		sashWeights = new int[] {
			80, 20
		};
		diagAndChargeSashWeights = new int[] {
			40, 60
		};
	} else {
		String state = memento.getString(CFG_VERTRELATION);
		if (state == null) {
			state = "80,20"; //$NON-NLS-1$
		}
		String[] sw = state.split(StringConstants.COMMA);
		sashWeights = new int[] {
			Integer.parseInt(sw[0]), Integer.parseInt(sw[1])
		};
		
		state = memento.getString(CFG_HORIZRELATION);
		if (state == null) {
			state = "40,60"; //$NON-NLS-1$
		}
		sw = state.split(StringConstants.COMMA);
		diagAndChargeSashWeights = new int[] {
			Integer.parseInt(sw[0]), Integer.parseInt(sw[1])
		};
		
	}
	super.init(site, memento);
}
 
Example 14
Source File: Item.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public static Item loadFrom ( final IMemento memento )
{
    if ( memento == null )
    {
        return null;
    }

    final String itemId = memento.getString ( "item.id" );
    final String connectionUri = memento.getString ( "connection.uri" );
    final String typeStr = memento.getString ( "type" );
    final Type type;

    if ( typeStr != null )
    {
        type = Type.valueOf ( typeStr );
    }
    else
    {
        type = Type.URI;
    }

    if ( itemId == null || connectionUri == null || type == null )
    {
        return null;
    }
    else
    {
        return new Item ( connectionUri, itemId, type );
    }
}
 
Example 15
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 16
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 17
Source File: EventHistoryView.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 18
Source File: OpenTypeSelectionDialog.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Object restoreItemFromMemento(final IMemento memento) {
	final String uri = memento.getString(MEMENTO_URI_KEY);
	if (!isNullOrEmpty(uri)) {
		final Optional<IEObjectDescription> result = tryFind(indexSupplier.get().getExportedObjects(),
				desc -> uri.equals(String.valueOf(desc.getEObjectURI())));
		if (result.isPresent()) {
			return searchKind.matches(result.get().getEClass()) ? result.get() : null;
		}
	}
	return null;
}
 
Example 19
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 20
Source File: InstalledUpdatesManager.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
private static InstalledUpdate createInstalledUpdateFor(IMemento installedUpdateChild) {
	String fileLocation = installedUpdateChild.getString(TAG_FILE_LOCATION);
	String version = installedUpdateChild.getString(TAG_VERSION);
	Version fileVersion = new Version(version);
	return new InstalledUpdate(fileLocation, fileVersion);
}