List of usage examples for org.eclipse.jface.resource StringConverter asArray
public static String[] asArray(String value) throws DataFormatException
From source file:gov.nasa.ensemble.common.ui.detail.DetailUtils.java
License:Open Source License
private static Collection<String> getFilterFlags(String property) { String string = PREFERENCES.getString(property); if (string == null) { return Collections.emptySet(); }/*from w w w . ja v a 2 s . com*/ String[] array = StringConverter.asArray(string); return new HashSet<String>(Arrays.asList(array)); }
From source file:org.eclipse.ui.internal.registry.PerspectiveRegistry.java
License:Open Source License
/** * Read children from the file system.//from ww w . j a v a 2 s.c o m */ private void loadCustom() { Reader reader = null; /* Get the entries from the Preference store */ IPreferenceStore store = WorkbenchPlugin.getDefault().getPreferenceStore(); /* Get the space-delimited list of custom perspective ids */ String customPerspectives = store.getString(IPreferenceConstants.PERSPECTIVES); String[] perspectivesList = StringConverter.asArray(customPerspectives); for (int i = 0; i < perspectivesList.length; i++) { try { String xmlString = store.getString(perspectivesList[i] + PERSP); if (xmlString != null && xmlString.length() != 0) { reader = new StringReader(xmlString); } else { throw new WorkbenchException(new Status(IStatus.ERROR, WorkbenchPlugin.PI_WORKBENCH, NLS.bind(WorkbenchMessages.get().Perspective_couldNotBeFound, perspectivesList[i]))); } // Restore the layout state. XMLMemento memento = XMLMemento.createReadRoot(reader); PerspectiveDescriptor newPersp = new PerspectiveDescriptor(null, null, null); newPersp.restoreState(memento); String id = newPersp.getId(); IPerspectiveDescriptor oldPersp = findPerspectiveWithId(id); if (oldPersp == null) { add(newPersp); } reader.close(); } catch (IOException e) { unableToLoadPerspective(null); } catch (WorkbenchException e) { unableToLoadPerspective(e.getStatus()); } } // Get the entries from files, if any // if -data @noDefault specified the state location may not be // initialized IPath path = WorkbenchPlugin.getDefault().getDataLocation(); if (path == null) { return; } File folder = path.toFile(); if (folder.isDirectory()) { File[] fileList = folder.listFiles(); int nSize = fileList.length; for (int nX = 0; nX < nSize; nX++) { File file = fileList[nX]; if (file.getName().endsWith(EXT)) { // get the memento InputStream stream = null; try { stream = new FileInputStream(file); reader = new BufferedReader(new InputStreamReader(stream, "utf-8")); //$NON-NLS-1$ // Restore the layout state. XMLMemento memento = XMLMemento.createReadRoot(reader); PerspectiveDescriptor newPersp = new PerspectiveDescriptor(null, null, null); newPersp.restoreState(memento); IPerspectiveDescriptor oldPersp = findPerspectiveWithId(newPersp.getId()); if (oldPersp == null) { add(newPersp); } // save to the preference store saveCustomPersp(newPersp, memento); // delete the file file.delete(); reader.close(); stream.close(); } catch (IOException e) { unableToLoadPerspective(null); } catch (WorkbenchException e) { unableToLoadPerspective(e.getStatus()); } } } } }