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

The following examples show how to use org.eclipse.ui.XMLMemento#save() . 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 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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();
}