diff options
author | Dejan Gloszic | 2005-04-29 23:07:11 +0000 |
---|---|---|
committer | Dejan Gloszic | 2005-04-29 23:07:11 +0000 |
commit | 92bbd6f0c60c69d9c58cc0ff0841526c13459439 (patch) | |
tree | e4198f1c5bd0a48202992840a41475fcda01c461 /org.eclipse.ui.cheatsheets | |
parent | 945e325f969c7fb2d11c1c20bb424d92b950a3e7 (diff) | |
download | eclipse.platform.ua-92bbd6f0c60c69d9c58cc0ff0841526c13459439.tar.gz eclipse.platform.ua-92bbd6f0c60c69d9c58cc0ff0841526c13459439.tar.xz eclipse.platform.ua-92bbd6f0c60c69d9c58cc0ff0841526c13459439.zip |
*** empty log message ***v20050502
Diffstat (limited to 'org.eclipse.ui.cheatsheets')
3 files changed, 125 insertions, 66 deletions
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetSaveHelper.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetSaveHelper.java index 87f4d4f76..8ca5e9d72 100644 --- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetSaveHelper.java +++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetSaveHelper.java @@ -27,8 +27,10 @@ import org.w3c.dom.*; import org.xml.sax.InputSource; public class CheatSheetSaveHelper { - //Get the path to the cheatsheet folder in the .metadata folder of workspace. + // Get the path to the cheatsheet folder in the .metadata folder of + // workspace. private IPath savePath; + protected Vector stateVector = new Vector(); /** @@ -36,10 +38,12 @@ public class CheatSheetSaveHelper { */ public CheatSheetSaveHelper() { super(); - savePath = Platform.getPluginStateLocation(CheatSheetPlugin.getPlugin()); + savePath = Platform + .getPluginStateLocation(CheatSheetPlugin.getPlugin()); } - private Properties createProperties(int currentItemNum, ArrayList items, boolean buttonIsDown, ArrayList expandRestoreStates, String csID) { + private Properties createProperties(int currentItemNum, ArrayList items, + boolean buttonIsDown, ArrayList expandRestoreStates, String csID) { Properties props = new Properties(); Hashtable subcompletedTable = new Hashtable(10); Hashtable subskippedTable = new Hashtable(10); @@ -56,9 +60,9 @@ public class CheatSheetSaveHelper { if (expandRestoreStates == null) expandRestoreStates = new ArrayList(); - //Assemble lists of expanded items and completed items. + // Assemble lists of expanded items and completed items. for (int i = 0; i < items.size(); i++) { - ViewItem item = (ViewItem)items.get(i); + ViewItem item = (ViewItem) items.get(i); if (item.isCompleted()) { completedList.add(Integer.toString(i)); } @@ -68,12 +72,14 @@ public class CheatSheetSaveHelper { if (item instanceof CoreItem) { CoreItem withsubs = (CoreItem) item; - ArrayList compList = withsubs.getListOfSubItemCompositeHolders(); + ArrayList compList = withsubs + .getListOfSubItemCompositeHolders(); if (compList != null) { StringBuffer skippedsubItems = new StringBuffer(); StringBuffer completedsubItems = new StringBuffer(); for (int j = 0; j < compList.size(); j++) { - SubItemCompositeHolder sch = (SubItemCompositeHolder) compList.get(j); + SubItemCompositeHolder sch = (SubItemCompositeHolder) compList + .get(j); if (sch.isCompleted()) completedsubItems.append(Integer.toString(j) + ","); //$NON-NLS-1$ if (sch.isSkipped()) @@ -96,7 +102,7 @@ public class CheatSheetSaveHelper { } } - //put expanded item list, completed list, button state + // put expanded item list, completed list, button state props.put(IParserTags.COMPLETED, completedList); props.put(IParserTags.EXPANDED, expandedList); props.put(IParserTags.EXPANDRESTORE, expandRestoreStates); @@ -110,7 +116,7 @@ public class CheatSheetSaveHelper { } /** - * Method parses attribute from named node map. Returns value as string. + * Method parses attribute from named node map. Returns value as string. */ private String getAttributeWithName(NamedNodeMap map, String name) { try { @@ -119,14 +125,17 @@ public class CheatSheetSaveHelper { return null; } } + /** - * Method parses all elements in nodelist, attempts to pull out same attribute from each. - * attributes are put into an array list in order they occur in node list elements. + * Method parses all elements in nodelist, attempts to pull out same + * attribute from each. attributes are put into an array list in order they + * occur in node list elements. */ private ArrayList getMultipleAttributesWithSameName(NodeList nl, String name) { ArrayList returnList = new ArrayList(); for (int i = 0; i < nl.getLength(); i++) { - String value = nl.item(i).getAttributes().getNamedItem(name).getNodeValue(); + String value = nl.item(i).getAttributes().getNamedItem(name) + .getNodeValue(); if (value != null) returnList.add(value); } @@ -134,7 +143,7 @@ public class CheatSheetSaveHelper { } public Path getStateFile(String csID) { - return new Path(savePath.append(csID+".xml").toOSString()); //$NON-NLS-1$ + return new Path(savePath.append(csID + ".xml").toOSString()); //$NON-NLS-1$ } public Properties loadState(String csID) { @@ -150,56 +159,83 @@ public class CheatSheetSaveHelper { readURL = filePath.toFile().toURL(); doc = readXMLFile(readURL); } catch (MalformedURLException mue) { - String message = NLS.bind(Messages.ERROR_CREATING_STATEFILE_URL, (new Object[] {readURL})); - IStatus status = new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, message, mue); + String message = NLS.bind(Messages.ERROR_CREATING_STATEFILE_URL, + (new Object[] { readURL })); + IStatus status = new Status(IStatus.ERROR, + ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, + message, mue); CheatSheetPlugin.getPlugin().getLog().log(status); return null; } if (doc != null) { - //Parse stuff from document here. + // Parse stuff from document here. Hashtable ht = null; Node rootnode = doc.getDocumentElement(); NamedNodeMap rootatts = rootnode.getAttributes(); String currentID = getAttributeWithName(rootatts, IParserTags.ID); - String number = getAttributeWithName(doc.getElementsByTagName(IParserTags.CURRENT).item(0).getAttributes(), IParserTags.ITEM); - ArrayList completeList = getMultipleAttributesWithSameName(doc.getElementsByTagName(IParserTags.COMPLETED), IParserTags.ITEM); - ArrayList expandedList = getMultipleAttributesWithSameName(doc.getElementsByTagName(IParserTags.EXPANDED), IParserTags.ITEM); - ArrayList expandRestoreList = getMultipleAttributesWithSameName(doc.getElementsByTagName(IParserTags.EXPANDRESTORE), IParserTags.ITEM); - String buttonState = getAttributeWithName(doc.getElementsByTagName(IParserTags.BUTTON).item(0).getAttributes(), IParserTags.BUTTONSTATE); - - NodeList nl = doc.getElementsByTagName(IParserTags.SUBITEMCOMPLETED); - if (nl != null) + String number = getAttributeWithName(doc.getElementsByTagName( + IParserTags.CURRENT).item(0).getAttributes(), + IParserTags.ITEM); + ArrayList completeList = getMultipleAttributesWithSameName(doc + .getElementsByTagName(IParserTags.COMPLETED), + IParserTags.ITEM); + ArrayList expandedList = getMultipleAttributesWithSameName(doc + .getElementsByTagName(IParserTags.EXPANDED), + IParserTags.ITEM); + ArrayList expandRestoreList = getMultipleAttributesWithSameName(doc + .getElementsByTagName(IParserTags.EXPANDRESTORE), + IParserTags.ITEM); + String buttonState = getAttributeWithName(doc.getElementsByTagName( + IParserTags.BUTTON).item(0).getAttributes(), + IParserTags.BUTTONSTATE); + + NodeList nl = doc + .getElementsByTagName(IParserTags.SUBITEMCOMPLETED); + if (nl != null) { subcompleted = new Hashtable(10); - for (int i = 0; i < nl.getLength(); i++) { - String item = getAttributeWithName(nl.item(i).getAttributes(), IParserTags.ITEM); - String subItems = getAttributeWithName(nl.item(i).getAttributes(), IParserTags.SUBITEM); - subcompleted.put(item, subItems); - } //end for nl + for (int i = 0; i < nl.getLength(); i++) { + String item = getAttributeWithName(nl.item(i) + .getAttributes(), IParserTags.ITEM); + String subItems = getAttributeWithName(nl.item(i) + .getAttributes(), IParserTags.SUBITEM); + subcompleted.put(item, subItems); + } + } // end for nl NodeList snl = doc.getElementsByTagName(IParserTags.SUBITEMSKIPPED); if (snl != null) { subskipped = new Hashtable(10); for (int i = 0; i < snl.getLength(); i++) { - String item = getAttributeWithName(snl.item(i).getAttributes(), IParserTags.ITEM); - String subItems = getAttributeWithName(snl.item(i).getAttributes(), IParserTags.SUBITEM); + String item = getAttributeWithName(snl.item(i) + .getAttributes(), IParserTags.ITEM); + String subItems = getAttributeWithName(snl.item(i) + .getAttributes(), IParserTags.SUBITEM); subskipped.put(item, subItems); - } //end for nl + } // end for nl } - NodeList csmDatanl = doc.getElementsByTagName(IParserTags.MANAGERDATA); + NodeList csmDatanl = doc + .getElementsByTagName(IParserTags.MANAGERDATA); if (csmDatanl != null) { ht = new Hashtable(30); for (int i = 0; i < csmDatanl.getLength(); i++) { String key = null; try { - key = getAttributeWithName(csmDatanl.item(i).getAttributes(), IParserTags.MANAGERDATAKEY); - String data = csmDatanl.item(i).getFirstChild().getNodeValue(); + key = getAttributeWithName(csmDatanl.item(i) + .getAttributes(), IParserTags.MANAGERDATAKEY); + String data = csmDatanl.item(i).getFirstChild() + .getNodeValue(); ht.put(key, data); - } catch(Exception e) { - String message = NLS.bind(Messages.ERROR_READING_MANAGERDATA_FROM_STATEFILE, (new Object[] {key, currentID})); - IStatus status = new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, message, e); + } catch (Exception e) { + String message = NLS + .bind( + Messages.ERROR_READING_MANAGERDATA_FROM_STATEFILE, + (new Object[] { key, currentID })); + IStatus status = new Status(IStatus.ERROR, + ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, + IStatus.OK, message, e); CheatSheetPlugin.getPlugin().getLog().log(status); } } @@ -219,8 +255,9 @@ public class CheatSheetSaveHelper { return returnProps; } - //Attempts to read an xml file from the provided url. Returns a Dom Document object if parses ok, - //returns null if the parse or read fails. + // Attempts to read an xml file from the provided url. Returns a Dom + // Document object if parses ok, + // returns null if the parse or read fails. private Document readXMLFile(URL url) { InputStream is = null; InputSource source = null; @@ -238,7 +275,8 @@ public class CheatSheetSaveHelper { return null; try { - DocumentBuilder documentBuilder = CheatSheetPlugin.getPlugin().getDocumentBuilder(); + DocumentBuilder documentBuilder = CheatSheetPlugin.getPlugin() + .getDocumentBuilder(); return documentBuilder.parse(source); } catch (Exception e) { } finally { @@ -257,7 +295,8 @@ public class CheatSheetSaveHelper { String csID = null; try { - DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + DocumentBuilder documentBuilder = DocumentBuilderFactory + .newInstance().newDocumentBuilder(); Document doc = documentBuilder.newDocument(); @@ -267,35 +306,43 @@ public class CheatSheetSaveHelper { Path filePath = getStateFile(csID); - ArrayList completedList = (ArrayList) properties.get(IParserTags.COMPLETED); - ArrayList expandedList = (ArrayList) properties.get(IParserTags.EXPANDED); - ArrayList expandRestoreList = (ArrayList) properties.get(IParserTags.EXPANDRESTORE); - Hashtable subcompletedTable = (Hashtable) properties.get(IParserTags.SUBITEMCOMPLETED); - Hashtable subskippedTable = (Hashtable) properties.get(IParserTags.SUBITEMSKIPPED); - - //Create the root element for the document now: + ArrayList completedList = (ArrayList) properties + .get(IParserTags.COMPLETED); + ArrayList expandedList = (ArrayList) properties + .get(IParserTags.EXPANDED); + ArrayList expandRestoreList = (ArrayList) properties + .get(IParserTags.EXPANDRESTORE); + Hashtable subcompletedTable = (Hashtable) properties + .get(IParserTags.SUBITEMCOMPLETED); + Hashtable subskippedTable = (Hashtable) properties + .get(IParserTags.SUBITEMSKIPPED); + + // Create the root element for the document now: Element root = doc.createElement(IParserTags.CHEATSHEET); root.setAttribute(IParserTags.ID, csID); doc.appendChild(root); - //create current element. + // create current element. Element cEl = doc.createElement(IParserTags.CURRENT); cEl.setAttribute(IParserTags.ITEM, number); root.appendChild(cEl); for (int j = 0; j < completedList.size(); j++) { Element compEl = doc.createElement(IParserTags.COMPLETED); - compEl.setAttribute(IParserTags.ITEM, (String) completedList.get(j)); + compEl.setAttribute(IParserTags.ITEM, (String) completedList + .get(j)); root.appendChild(compEl); } for (int j = 0; j < expandedList.size(); j++) { Element expandEl = doc.createElement(IParserTags.EXPANDED); - expandEl.setAttribute(IParserTags.ITEM, (String) expandedList.get(j)); + expandEl.setAttribute(IParserTags.ITEM, (String) expandedList + .get(j)); root.appendChild(expandEl); } for (int j = 0; j < expandRestoreList.size(); j++) { Element eRel = doc.createElement(IParserTags.EXPANDRESTORE); - eRel.setAttribute(IParserTags.ITEM, (String) expandRestoreList.get(j)); + eRel.setAttribute(IParserTags.ITEM, (String) expandRestoreList + .get(j)); root.appendChild(eRel); } if (subcompletedTable != null) { @@ -305,7 +352,8 @@ public class CheatSheetSaveHelper { String subItemNum = (String) subcompletedTable.get(itemNum); if (itemNum == null || subItemNum == null) continue; - Element eRel = doc.createElement(IParserTags.SUBITEMCOMPLETED); + Element eRel = doc + .createElement(IParserTags.SUBITEMCOMPLETED); eRel.setAttribute(IParserTags.ITEM, itemNum); eRel.setAttribute(IParserTags.SUBITEM, subItemNum); root.appendChild(eRel); @@ -318,24 +366,27 @@ public class CheatSheetSaveHelper { String subItemNum = (String) subskippedTable.get(itemNum); if (itemNum == null || subItemNum == null) continue; - Element eRel = doc.createElement(IParserTags.SUBITEMSKIPPED); + Element eRel = doc + .createElement(IParserTags.SUBITEMSKIPPED); eRel.setAttribute(IParserTags.ITEM, itemNum); eRel.setAttribute(IParserTags.SUBITEM, subItemNum); root.appendChild(eRel); } } Element bel = doc.createElement(IParserTags.BUTTON); - bel.setAttribute(IParserTags.BUTTONSTATE, (String) properties.get(IParserTags.BUTTON)); + bel.setAttribute(IParserTags.BUTTONSTATE, (String) properties + .get(IParserTags.BUTTON)); root.appendChild(bel); - //Store cheatsheet data here. - Hashtable managerData = (Hashtable)csm.getData(); + // Store cheatsheet data here. + Hashtable managerData = (Hashtable) csm.getData(); if (managerData != null) { Enumeration e = managerData.keys(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); String data = (String) managerData.get(key); - Element csmDataTag = doc.createElement(IParserTags.MANAGERDATA); + Element csmDataTag = doc + .createElement(IParserTags.MANAGERDATA); csmDataTag.setAttribute(IParserTags.MANAGERDATAKEY, key); Text t = doc.createTextNode(data); csmDataTag.appendChild(t); @@ -344,20 +395,27 @@ public class CheatSheetSaveHelper { } StreamResult streamResult = new StreamResult(filePath.toFile()); - + DOMSource domSource = new DOMSource(doc); - Transformer transformer = TransformerFactory.newInstance().newTransformer(); + Transformer transformer = TransformerFactory.newInstance() + .newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$ transformer.transform(domSource, streamResult); } catch (Exception e) { - String message = NLS.bind(Messages.ERROR_SAVING_STATEFILE_URL, (new Object[] {csID})); - IStatus status = new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, message, e); + String message = NLS.bind(Messages.ERROR_SAVING_STATEFILE_URL, + (new Object[] { csID })); + IStatus status = new Status(IStatus.ERROR, + ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, + message, e); CheatSheetPlugin.getPlugin().getLog().log(status); } } - public void saveState(int currentItemNum, ArrayList items, boolean buttonIsDown, ArrayList expandRestoreStates, String csID, CheatSheetManager csm) { - Properties properties = createProperties(currentItemNum, items, buttonIsDown, expandRestoreStates, csID); + public void saveState(int currentItemNum, ArrayList items, + boolean buttonIsDown, ArrayList expandRestoreStates, String csID, + CheatSheetManager csm) { + Properties properties = createProperties(currentItemNum, items, + buttonIsDown, expandRestoreStates, csID); saveState(properties, csm); } diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetPage.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetPage.java index 75f3f9dbd..19a98c9b7 100644 --- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetPage.java +++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetPage.java @@ -80,7 +80,7 @@ public class CheatSheetPage extends Page { * @param parent the SWT parent for the title area composite */ protected String getTitle() { - if(cheatSheet != null & cheatSheet.getTitle() != null) + if(cheatSheet != null && cheatSheet.getTitle() != null) return cheatSheet.getTitle(); else return ICheatSheetResource.EMPTY_STRING; diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/Page.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/Page.java index 6e83c2858..c38246c5e 100644 --- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/Page.java +++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/Page.java @@ -74,6 +74,7 @@ public abstract class Page { toolkit = new FormToolkit(parent.getDisplay()); CheatSheetStopWatch.printLapTime("Page.createInfoArea()", "Time in Page.createInfoArea() after new FormToolkit(): "); //$NON-NLS-1$ //$NON-NLS-2$ form = toolkit.createScrolledForm(parent); + form.setData("novarrows", Boolean.TRUE); form.setDelayedReflow(true); CheatSheetStopWatch.printLapTime("Page.createInfoArea()", "Time in Page.createInfoArea() after createScrolledForm(): "); //$NON-NLS-1$ //$NON-NLS-2$ form.setLayoutData(new GridData(GridData.FILL_BOTH)); |