Java Code Examples for org.eclipse.ui.XMLMemento#createWriteRoot()

The following examples show how to use org.eclipse.ui.XMLMemento#createWriteRoot() . 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: BugExplorerView.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void init(IViewSite site, IMemento memento) throws PartInitException {
    viewMemento = memento;
    if (memento == null) {
        IDialogSettings dialogSettings = FindbugsPlugin.getDefault().getDialogSettings();
        String persistedMemento = dialogSettings.get(TAG_MEMENTO);
        if (persistedMemento == null) {
            // See bug 2504068. First time user opens a view, no settings
            // are defined
            // but we still need to enforce initialisation of content
            // provider
            // which can only happen if memento is not null
            memento = XMLMemento.createWriteRoot("bugExplorer");
        } else {
            try {
                memento = XMLMemento.createReadRoot(new StringReader(persistedMemento));
            } catch (WorkbenchException e) {
                // don't do anything. Simply don't restore the settings
            }
        }
    }
    super.init(site, memento);
}
 
Example 2
Source File: BugExplorerView.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void dispose() {
    // XXX see https://bugs.eclipse.org/bugs/show_bug.cgi?id=223068
    XMLMemento memento = XMLMemento.createWriteRoot("bugExplorer"); //$NON-NLS-1$
    saveState(memento);
    StringWriter writer = new StringWriter();
    try {
        memento.save(writer);
        IDialogSettings dialogSettings = FindbugsPlugin.getDefault().getDialogSettings();
        dialogSettings.put(TAG_MEMENTO, writer.getBuffer().toString());
    } catch (IOException e) {
        // don't do anything. Simply don't store the settings
    }

    if (selectionListener != null) {
        getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener(selectionListener);
        selectionListener = null;
    }
    super.dispose();
}
 
Example 3
Source File: FilteredItemsSelectionDialog.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * Stores dialog settings.
 *
 * @param settings
 *            settings used to store dialog
 */
protected void storeDialog(IDialogSettings settings) {
	settings.put(SHOW_STATUS_LINE, toggleStatusLineAction.isChecked());

	XMLMemento memento = XMLMemento.createWriteRoot(HISTORY_SETTINGS);
	this.contentProvider.saveHistory(memento);
	StringWriter writer = new StringWriter();
	try {
		memento.save(writer);
		settings.put(HISTORY_SETTINGS, writer.getBuffer().toString());
	} catch (IOException e) {
		// Simply don't store the settings
		StatusManager
				.getManager()
				.handle(
						new Status(
								IStatus.ERROR,
								PlatformUI.PLUGIN_ID,
								IStatus.ERROR,
								WorkbenchMessages.FilteredItemsSelectionDialog_storeError,
								e));
	}
}
 
Example 4
Source File: IndexedJsniJavaRefTest.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public void testSave() {
  XMLMemento memento = XMLMemento.createWriteRoot("JavaRef");

  // Set up a test JsniJavaRef to serialize
  JsniJavaRef ref = JsniJavaRef.parse("@com.hello.Hello::sayHi(Ljava/lang/String;)");
  ref.setOffset(25);
  ref.setSource(new Path("/MyProject/src/com/hello/Hello.java"));
  IndexedJsniJavaRef indexedRef = new IndexedJsniJavaRef(ref);

  indexedRef.save(memento);
  assertEquals("@com.hello.Hello::sayHi(Ljava/lang/String;)",
      memento.getTextData());
  assertEquals(25, memento.getInteger("offset").intValue());
  assertEquals("/MyProject/src/com/hello/Hello.java",
      memento.getString("source"));
}
 
Example 5
Source File: CompilationUnitResourceDependencyIndex.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public void saveIndex() {
  XMLMemento memento = XMLMemento.createWriteRoot(TAG_ROOT);
  persistIndex(memento);

  File indexFile = getIndexFile();
  FileWriter writer = null;
  try {
    try {
      writer = new FileWriter(indexFile);
      memento.save(writer);
    } finally {
      if (writer != null) {
        writer.close();
      }
    }
  } catch (IOException e) {
    CorePluginLog.logError(e, "Error saving index " + indexName);

    // Make sure we remove any partially-written file
    if (indexFile.exists()) {
      indexFile.delete();
    }
  }
}
 
Example 6
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 = XMLMemento.createWriteRoot(TAG_JAVA_REFS);
  saveIndex(memento);

  FileWriter writer = null;
  try {
    try {
      writer = new FileWriter(getIndexFile());
      memento.save(writer);
    } finally {
      if (writer != null) {
        writer.close();
      }
    }
  } catch (IOException e) {
    GWTPluginLog.logError(e, "Error saving search index");
  }
}
 
Example 7
Source File: FilteredTypesSelectionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void storeDialog(IDialogSettings settings) {
	super.storeDialog(settings);

	if (! BUG_184693) {
		settings.put(SHOW_CONTAINER_FOR_DUPLICATES, fShowContainerForDuplicatesAction.isChecked());
	}

	if (fFilterActionGroup != null) {
		XMLMemento memento= XMLMemento.createWriteRoot("workingSet"); //$NON-NLS-1$
		fFilterActionGroup.saveState(memento);
		fFilterActionGroup.dispose();
		StringWriter writer= new StringWriter();
		try {
			memento.save(writer);
			settings.put(WORKINGS_SET_SETTINGS, writer.getBuffer().toString());
		} catch (IOException e) {
			// don't do anything. Simply don't store the settings
			JavaPlugin.log(e);
		}
	}
}
 
Example 8
Source File: GlobalsTwoPanelElementSelector2.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void storeDialog(IDialogSettings settings) {
    super.storeDialog(settings);

    XMLMemento memento = XMLMemento.createWriteRoot("workingSet"); //$NON-NLS-1$
    workingSetFilterActionGroup.saveState(memento);
    workingSetFilterActionGroup.dispose();
    StringWriter writer = new StringWriter();
    try {
        memento.save(writer);
        settings.put(WORKINGS_SET_SETTINGS, writer.getBuffer().toString());
    } catch (IOException e) {
        StatusManager.getManager().handle(
                new Status(IStatus.ERROR, AnalysisPlugin.getPluginID(), IStatus.ERROR, "", e)); //$NON-NLS-1$
        // don't do anything. Simply don't store the settings
    }
}
 
Example 9
Source File: ProfileManager.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Play export dialog and do the export 
 * 
 * @param prof - null to export all or the given profile
 * @param pm   - profile manager to get profiles from (when 'prof' == null)
 */
public static void exportProfiles(Shell shell, IProfile prof, ProfileManager pm) {
    String title = prof==null ? Messages.ProfileManager_ExportProfile : Messages.ProfileManager_ExportProfiles;
    String s = SWTFactory.browseFile(shell, true, title, new String[]{"*.xml"}, importExportPath); //$NON-NLS-1$
    if (s != null) {
        File f = new File(s);
        if (f.exists()) {
            if (!SWTFactory.YesNoQuestion(shell, title, 
                                          String.format(Messages.ProfileManager_ReplaceQuestion, s))) 
            {
                return;
            }
        }

        importExportPath = f.getParentFile().getAbsolutePath();
        XMLMemento memento = XMLMemento.createWriteRoot("tagExportedFormatterProfiles"); //$NON-NLS-1$
        int memNum = 0;
        int total = prof == null ? pm.size() : 1;
        for (int num=0; num < total; ++num) {
            IProfile ip = prof == null ? pm.get(num) : prof;
            IMemento childMem = memento.createChild(XML_FORMATTER_PROFILE_SECTION + memNum++);
            ip.toMemento(childMem);
        }
        try {
            f.delete();
            FileWriter fw = new FileWriter(f);
            memento.save(fw);
            fw.close();
        } catch(Exception e) {
            LogHelper.logError(e);
        }
    }
}
 
Example 10
Source File: InstalledUpdatesManager.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public void saveInstalledUpdatesRegistry(InstalledUpdatesRegistry installedUpdatesRegistry) throws IOException {
	XMLMemento memento = XMLMemento.createWriteRoot(TAG_INSTALLED_UPDATES);
	saveInstalledUpdatesRegistry(memento, installedUpdatesRegistry);
	
	FileWriter writer = new FileWriter(getInstalledUpdatesRegistryFile());
    memento.save(writer);
}
 
Example 11
Source File: StatechartDefinitionSection.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void saveState(IMemento memento) {
	if (memento == null) {
		memento = XMLMemento.createWriteRoot(getFactoryId());
	}
	setMementoProperties(memento);
	saveCurrentMemento(memento);
}
 
Example 12
Source File: JsniJavaRefParamTypeTest.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public void testSave() {
  XMLMemento memento = XMLMemento.createWriteRoot("JavaRef");

  // Set up a test JsniJavaRefParamType to serialize
  JsniJavaRefParamType ref = JsniJavaRefParamType.parse(new Path(
      "/MyProject/src/com/hello/Hello.java"), 25, "Ljava/lang/String;");

  ref.save(memento);
  assertEquals("Ljava/lang/String;", memento.getTextData());
  assertEquals(25, memento.getInteger("offset").intValue());
  assertEquals("/MyProject/src/com/hello/Hello.java",
      memento.getString("source"));
}
 
Example 13
Source File: InputURLDialog.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected void saveMemento() {
	XMLMemento memento = XMLMemento.createWriteRoot(URLS);
	saveList(memento);
	File file = UIEplPlugin.getDefault().getStateLocation().append(URLS).addFileExtension(XML).toFile();
	try {
		FileWriter writer = new FileWriter(file);
		memento.save(writer);
	} catch (IOException e) {
		IdeLog.logError(UIEplPlugin.getDefault(), e);
	}

}
 
Example 14
Source File: TypeSelectionComponent.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void disposeComponent() {
	if (fFilterActionGroup != null) {
		XMLMemento memento= XMLMemento.createWriteRoot("workingSet"); //$NON-NLS-1$
		fFilterActionGroup.saveState(memento);
		fFilterActionGroup.dispose();
		StringWriter writer= new StringWriter();
		try {
			memento.save(writer);
			fSettings.put(WORKINGS_SET_SETTINGS, writer.getBuffer().toString());
		} catch (IOException e) {
			// don't do anything. Simply don't store the settings
		}
	}
}
 
Example 15
Source File: PackageExplorerPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void dispose() {
	XMLMemento memento= XMLMemento.createWriteRoot("packageExplorer"); //$NON-NLS-1$
	saveState(memento);
	StringWriter writer= new StringWriter();
	try {
		memento.save(writer);
		fDialogSettings.put(TAG_MEMENTO, writer.getBuffer().toString());
	} catch (IOException e) {
		// don't do anything. Simply don't store the settings
	}

	if (fContextMenu != null && !fContextMenu.isDisposed())
		fContextMenu.dispose();

	getSite().getPage().removePartListener(fLinkWithEditorListener); // always remove even if we didn't register

	JavaPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this);
	if (fViewer != null)
		fViewer.removeTreeListener(fExpansionListener);

	if (fActionSet != null)
		fActionSet.dispose();
	if (fFilterUpdater != null)
		ResourcesPlugin.getWorkspace().removeResourceChangeListener(fFilterUpdater);
	if (fWorkingSetModel != null)
		fWorkingSetModel.dispose();

	super.dispose();
}
 
Example 16
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();
}