Mercurial > hg > thermostat-tools-eclipse
changeset 40:430763b455c1
Update xml based on UI changes
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Fri, 06 Dec 2013 13:56:21 -0500 |
parents | ceb07241b7cb |
children | 2d3178148dd6 |
files | src/com/redhat/thermostat/plugin/eclipse/editor/CommandEditPage.java src/com/redhat/thermostat/plugin/eclipse/model/PluginModel.java |
diffstat | 2 files changed, 66 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/com/redhat/thermostat/plugin/eclipse/editor/CommandEditPage.java Thu Dec 05 23:01:00 2013 -0500 +++ b/src/com/redhat/thermostat/plugin/eclipse/editor/CommandEditPage.java Fri Dec 06 13:56:21 2013 -0500 @@ -58,13 +58,18 @@ @Override public boolean isDirty() { - // TODO check with model - return false; + Command commandModel = model.getCommand(command); + // TODO change this is-content-different into is-content-dirty + boolean result = !(commandName.getText().equals(commandModel.name) + && commandDescription.getText().equals(commandModel.description) + && commandUsage.getText().equals(commandModel.usage)); + // System.out.println("isDirty [" + command + "]: " + result); + return result; } @Override public void commit(boolean onSave) { - // TODO how does this interact with model? + updateModel(); } @Override @@ -130,6 +135,7 @@ toolkit.createLabel(basicContents, "Name:"); commandName = toolkit.createText(basicContents, "<command name here>"); + commandName.setEditable(false); commandName.setLayoutData(fillHorizontally); toolkit.createLabel(basicContents, "Usage:"); @@ -162,4 +168,12 @@ commandUsage.setText(commandModel.usage); } + private void updateModel() { + Command updated; + if (command.equals(commandName.getText())) { + updated = new Command(commandName.getText(), commandDescription.getText(), commandUsage.getText()); + model.updateCommand(updated); + } + } + } \ No newline at end of file
--- a/src/com/redhat/thermostat/plugin/eclipse/model/PluginModel.java Thu Dec 05 23:01:00 2013 -0500 +++ b/src/com/redhat/thermostat/plugin/eclipse/model/PluginModel.java Fri Dec 06 13:56:21 2013 -0500 @@ -197,12 +197,58 @@ Node commandNameNode = doc.createElement("name"); commandNode.appendChild(commandNameNode); - Node commandNameTextNode = doc.createTextNode(name); - commandNameNode.appendChild(commandNameTextNode); + commandNameNode.setTextContent(name); fireModelChanged(); } + public void updateCommand(Command command) { + // FIXME sanitize name; it should be alphanumeric only! + + XPath xpath = xPathfactory.newXPath(); + String expressionString; + XPathExpression expr; + Node node; + + try { + // find a command with a child 'name' having the matching text + expressionString = "/plugin/commands/command[name/text() = '" + command.name + "']"; + expr = xpath.compile(expressionString); + node = (Node) expr.evaluate(doc, XPathConstants.NODE); + Node commandNode = node; + + Node descriptionNode = null; + Node usageNode = null; + + NodeList childNodes = commandNode.getChildNodes(); + for (int i = 0; i < childNodes.getLength(); i++) { + node = childNodes.item(i); + if (node.getNodeName().equals("description")) { + descriptionNode = node; + } else if (node.getNodeName().equals("usage")) { + usageNode = node; + } + } + + if (descriptionNode == null) { + descriptionNode = doc.createElement("description"); + commandNode.appendChild(descriptionNode); + } + + descriptionNode.setTextContent(command.description); + + if (usageNode == null) { + usageNode = doc.createElement("usage"); + commandNode.appendChild(usageNode); + } + + usageNode.setTextContent(command.usage); + + } catch (XPathExpressionException e) { + throw new AssertionError("bad xpath expression", e); + } + } + public void removeCommand(String name) { // FIXME sanitize name; it should be alphanumeric only! @@ -225,6 +271,7 @@ throw new AssertionError(e); } } + public void addModelChangeListener(PluginModelChangeListener listener) { listeners.add(listener); }