diff --git a/depotclient/org.universaal.tools.xmlEditor/src/xmleditor/editors/FieldsPage.java b/depotclient/org.universaal.tools.xmlEditor/src/xmleditor/editors/FieldsPage.java new file mode 100644 index 0000000000000000000000000000000000000000..c27528723e4427d0930f59dca49130d9fe278dc8 --- /dev/null +++ b/depotclient/org.universaal.tools.xmlEditor/src/xmleditor/editors/FieldsPage.java @@ -0,0 +1,169 @@ +package xmleditor.editors; + +import java.util.ArrayList; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +import xmleditor.model.ProjectModel; + +public class FieldsPage extends Composite { + + private XmlEditor parent; + private Text projectName, developerName, date, url, svnUrl, tags; + private StyledText description; + private ProjectModel model; + + /** + * @wbp.parser.constructor + */ + public FieldsPage(Composite container){ + super(container, SWT.NONE); + } + + public FieldsPage(XmlEditor parent, ProjectModel model, Composite container){ + super(container, SWT.NONE); + this.parent = parent; + this.model = model; + + FieldListener listen = new FieldListener(); + + this.setLayout(new GridLayout(2, false)); + + Label lblProjectName = new Label(this, SWT.NONE); + lblProjectName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + lblProjectName.setText("Project Name"); + + projectName = new Text(this, SWT.BORDER); + projectName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + + Label lblDeveloper = new Label(this, SWT.NONE); + lblDeveloper.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + lblDeveloper.setText("Developer"); + + developerName = new Text(this, SWT.BORDER); + developerName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + + + Label lblDate = new Label(this, SWT.NONE); + lblDate.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + lblDate.setText("Date"); + + date = new Text(this, SWT.BORDER); + date.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + + + Label lblUrl = new Label(this, SWT.NONE); + lblUrl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + lblUrl.setText("URL"); + + url = new Text(this, SWT.BORDER); + url.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + + + Label lblSvnUrl = new Label(this, SWT.NONE); + lblSvnUrl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + lblSvnUrl.setText("SVN URL"); + + svnUrl = new Text(this, SWT.BORDER); + svnUrl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + + + Label lblTags = new Label(this, SWT.NONE); + lblTags.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + lblTags.setText("Tags"); + lblTags.setToolTipText("Enter project tags, separated by commas. E.g. \"tag, tag2\""); + + tags = new Text(this, SWT.BORDER); + tags.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); + + + Label lblDescription = new Label(this, SWT.NONE); + lblDescription.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + lblDescription.setText("Description"); + + description = new StyledText(this, SWT.BORDER | SWT.WRAP); + description.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); + + setFields(); + + description.addModifyListener(listen); + svnUrl.addModifyListener(listen); + url.addModifyListener(listen); + date.addModifyListener(listen); + developerName.addModifyListener(listen); + projectName.addModifyListener(listen); + tags.addModifyListener(listen); + } + + public void setFields(){ + projectName.setText(model.getpName()); + developerName.setText(model.getpDev()); + date.setText(model.getpDate()); + url.setText(model.getpUrl()); + svnUrl.setText(model.getpSvnUrl()); + description.setText(model.getpDesc()); + tags.setText(getTagsStringFromModel()); + } + + class FieldListener implements ModifyListener{ + + @Override + public void modifyText(ModifyEvent e) { +// parent.isDirty = true; + parent.fieldsModified(); + + if(e.getSource()==projectName){ + model.setpName(projectName.getText()); + }else if(e.getSource() == developerName){ + model.setpDev(developerName.getText()); + }else if(e.getSource()==date){ + model.setpDate(date.getText()); + }else if(e.getSource()==url){ + model.setpUrl(url.getText()); + }else if(e.getSource()==svnUrl){ + model.setpSvnUrl(svnUrl.getText()); + }else if(e.getSource()==description){ + model.setpDesc(description.getText()); + }else if(e.getSource()==tags) + model.setpTags(getTagsFromFields()); + } + } + + private ArrayList<String> getTagsFromFields(){ + ArrayList<String> result = new ArrayList<String>(); + String string = tags.getText(); + String tempString=""; + int prevComma=0; + int nextComma=string.indexOf(','); + while(nextComma>=0){ + tempString=string.substring(prevComma, nextComma); + prevComma=nextComma+1; + nextComma = string.indexOf(',', prevComma); + result.add(tempString.trim()); + } + result.add((string.substring(prevComma)).trim()); + return result; + } + + private String getTagsStringFromModel(){ + String result=""; + ArrayList<String> tags = model.getpTags(); + for(int i=0; i<tags.size();i++){ + result += tags.get(i); + if(i!=tags.size()-1){ + result += ", "; + } + } + return result; + } + + +} \ No newline at end of file diff --git a/depotclient/org.universaal.tools.xmlEditor/src/xmleditor/editors/SourcePage.java b/depotclient/org.universaal.tools.xmlEditor/src/xmleditor/editors/SourcePage.java new file mode 100644 index 0000000000000000000000000000000000000000..9907ad948d6a796d12cc4e0a3d189234e6f0af1d --- /dev/null +++ b/depotclient/org.universaal.tools.xmlEditor/src/xmleditor/editors/SourcePage.java @@ -0,0 +1,191 @@ +package xmleditor.editors; + +import java.io.IOException; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.ArrayList; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.eclipse.wst.sse.ui.StructuredTextEditor; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import xmleditor.model.ProjectModel; + +public class SourcePage extends StructuredTextEditor { + + private ProjectModel model; + private XmlEditor parent; + private Document doc; + private boolean isPageModified; + + public SourcePage(XmlEditor parent, ProjectModel model, Document doc){ + this.parent = parent; + this.model = model; + this.doc = doc; + this.isPageModified = false; + + } + + public void updateModelFromXml(){ + + try { + String string = this.getDocumentProvider().getDocument(this.getEditorInput()).get(); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + doc = builder.parse(new InputSource(new StringReader(string))); + } catch (SAXException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ParserConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + NodeList nList; + Element node; + String name, developer, date, url, svnurl, desc; + ArrayList<String> tags = new ArrayList<String>(); + + nList = doc.getElementsByTagName("name"); + node = (Element) nList.item(0); + name =node.getFirstChild().getNodeValue(); + + nList = doc.getElementsByTagName("developer"); + node = (Element) nList.item(0); + developer = node.getFirstChild().getNodeValue(); + + nList = doc.getElementsByTagName("date"); + node = (Element) nList.item(0); + date = node.getFirstChild().getNodeValue(); + + nList = doc.getElementsByTagName("url"); + node = (Element) nList.item(0); + url = node.getFirstChild().getNodeValue(); + + nList = doc.getElementsByTagName("svnurl"); + node = (Element) nList.item(0); + svnurl = node.getFirstChild().getNodeValue(); + + nList = doc.getElementsByTagName("description"); + node = (Element) nList.item(0); + desc = node.getFirstChild().getNodeValue(); + + nList = doc.getElementsByTagName("tag"); + for(int i=0; i<nList.getLength(); i++){ + node = (Element) nList.item(i); + tags.add(node.getFirstChild().getNodeValue()); + } + + if(!name.equals(model.getpName())) + model.setpName(name); + if(!developer.equals(model.getpDev())) + model.setpDev(developer); + if(!date.equals(model.getpDate())) + model.setpDate(date); + if(!url.equals(model.getpUrl())) + model.setpUrl(url); + if(!svnurl.equals(model.getpSvnUrl())) + model.setpSvnUrl(svnurl); + if(!desc.equals(model.getpDesc())) + model.setpDesc(desc); + + model.setpTags(tags); + + } + + public void updateXmlFromModel(){ + + NodeList nList; + Element node; + + try{ + nList = doc.getElementsByTagName("name"); + node = (Element) nList.item(0); + node.setTextContent(model.getpName()); + + nList = doc.getElementsByTagName("developer"); + node = (Element) nList.item(0); + node.setTextContent(model.getpDev()); + + nList = doc.getElementsByTagName("date"); + node = (Element) nList.item(0); + node.setTextContent(model.getpDate()); + + nList = doc.getElementsByTagName("url"); + node = (Element) nList.item(0); + node.setTextContent(model.getpUrl()); + + nList = doc.getElementsByTagName("svnurl"); + node = (Element) nList.item(0); + node.setTextContent(model.getpSvnUrl()); + + nList = doc.getElementsByTagName("description"); + node = (Element) nList.item(0); + node.setTextContent(model.getpDesc()); + + ArrayList<String> tempTags = model.getpTags(); + nList = doc.getElementsByTagName("tags"); + Node oldTags = (Element) nList.item(0); + Node project = node.getParentNode(); + + + doc.normalizeDocument(); + + Node newTags = doc.createElement("tags"); + + for(int i=0; i<tempTags.size(); i++){ + Element el = doc.createElement("tag"); + el.appendChild(doc.createTextNode(tempTags.get(i))); + newTags.appendChild(el); + } + project.replaceChild(newTags, oldTags); + + + }catch(Exception e){ + e.printStackTrace(); + } + + try { + Source source = new DOMSource(doc); + StringWriter stringWriter = new StringWriter(); + Result result = new StreamResult(stringWriter); + TransformerFactory factory2 = TransformerFactory.newInstance(); + Transformer transformer; + transformer = factory2.newTransformer(); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); + transformer.setOutputProperty(OutputKeys.STANDALONE, "yes"); + + transformer.transform(source, result); + String str = stringWriter.getBuffer().toString(); + this.getDocumentProvider().getDocument(parent.getEditorInput()).set(str); + } catch (TransformerConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (TransformerException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} diff --git a/depotclient/org.universaal.tools.xmlEditor/src/xmleditor/editors/XmlEditor.java b/depotclient/org.universaal.tools.xmlEditor/src/xmleditor/editors/XmlEditor.java index b855938c6c15b116540d0543f1efa802ad0ccd3c..00618ba8ac71f93d20e950afb42530a0eb86fb4d 100644 --- a/depotclient/org.universaal.tools.xmlEditor/src/xmleditor/editors/XmlEditor.java +++ b/depotclient/org.universaal.tools.xmlEditor/src/xmleditor/editors/XmlEditor.java @@ -58,20 +58,19 @@ import xmleditor.model.ProjectModel; public class XmlEditor extends MultiPageEditorPart implements IResourceChangeListener{ public static final String ID = "xmleditor.editors.EditorPart1"; //$NON-NLS-1$ - protected StructuredTextEditor structured; private ProjectModel model; - private Text projectName; - private Text developerName; - private Text date, url, svnUrl, tags; - private StyledText description; private Document doc; private IEditorInput input; + - private boolean isDirty, isPageModified; + private FieldsPage fields; + private SourcePage source; + + public boolean isPageModified; public XmlEditor() { super(); - isDirty=false; +// isDirty=false; isPageModified = false; ResourcesPlugin.getWorkspace().addResourceChangeListener(this); } @@ -88,7 +87,7 @@ public class XmlEditor extends MultiPageEditorPart implements IResourceChangeLis @Override protected IEditorSite createSite(IEditorPart page) { IEditorSite site = null; - if (page == structured) { + if (page == source) { site = new MultiPageEditorSite(this, page) { public String getId() { // Sets this ID so nested editor is configured for XML source @@ -115,108 +114,20 @@ public class XmlEditor extends MultiPageEditorPart implements IResourceChangeLis @Override protected void createPages() { - createPage2(); - createPage1(); - setActivePage(1); - } - - - - /** - * Creates the page containing the textfields. This is the active page when - * the editor opens. - */ - void createPage1(){ - - FieldListener listen = new FieldListener(); - - Composite container = new Composite(getContainer(), SWT.NONE); - container.setLayout(new GridLayout(2, false)); - - Label lblProjectName = new Label(container, SWT.NONE); - lblProjectName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); - lblProjectName.setText("Project Name"); - - projectName = new Text(container, SWT.BORDER); - projectName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - - Label lblDeveloper = new Label(container, SWT.NONE); - lblDeveloper.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); - lblDeveloper.setText("Developer"); - - developerName = new Text(container, SWT.BORDER); - developerName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - - - Label lblDate = new Label(container, SWT.NONE); - lblDate.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); - lblDate.setText("Date"); - - date = new Text(container, SWT.BORDER); - date.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - - - Label lblUrl = new Label(container, SWT.NONE); - lblUrl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); - lblUrl.setText("URL"); - - url = new Text(container, SWT.BORDER); - url.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - - - Label lblSvnUrl = new Label(container, SWT.NONE); - lblSvnUrl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); - lblSvnUrl.setText("SVN URL"); - - svnUrl = new Text(container, SWT.BORDER); - svnUrl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - - - Label lblTags = new Label(container, SWT.NONE); - lblTags.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); - lblTags.setText("Tags"); - lblTags.setToolTipText("Enter project tags, separated by commas. E.g. \"tag, tag2\""); - - tags = new Text(container, SWT.BORDER); - tags.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); - - - Label lblDescription = new Label(container, SWT.NONE); - lblDescription.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); - lblDescription.setText("Description"); - - description = new StyledText(container, SWT.BORDER | SWT.WRAP); - description.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); - - - - int index = addPage(container); - setPageText(index, "Forms"); - - setFields(); - - description.addModifyListener(listen); - svnUrl.addModifyListener(listen); - url.addModifyListener(listen); - date.addModifyListener(listen); - developerName.addModifyListener(listen); - projectName.addModifyListener(listen); - tags.addModifyListener(listen); - } - - - /** - * Creates the page containing the source of the xml-file - */ - void createPage2(){ - try{ - structured = new StructuredTextEditor(); - int index = addPage(structured, getEditorInput()); + int index; + source = new SourcePage(this, model, doc); + fields = new FieldsPage(this, model, getContainer()); + + try { + index = addPage(source, getEditorInput()); setPageText(index, "Source"); - }catch(Exception e){ - + index = addPage(fields); + setPageText(index, "Fields"); + setActivePage(1); + } catch (PartInitException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } - } /** @@ -228,17 +139,18 @@ public class XmlEditor extends MultiPageEditorPart implements IResourceChangeLis protected void pageChange(int newPage){ switch(newPage){ case 0: - if(isDirty){ - updateXmlFromModel(); + if(isDirty()){ + source.updateXmlFromModel(); } break; case 1: if(isPageModified){ - updateFieldsFromXml(); + source.updateModelFromXml(); + fields.setFields(); } break; } - isDirty=false; + isPageModified=false; super.pageChange(newPage); } @@ -248,13 +160,15 @@ public class XmlEditor extends MultiPageEditorPart implements IResourceChangeLis @Override public void doSave(IProgressMonitor monitor) { if(getActivePage() == 0){ - updateFieldsFromXml(); - updateXmlFromModel(); + source.updateModelFromXml(); + source.updateXmlFromModel(); + fields.setFields(); }else{ - updateXmlFromModel(); + source.updateXmlFromModel(); } isPageModified=false; - structured.doSave(monitor); + source.doSave(monitor); + } /** @@ -271,13 +185,13 @@ public class XmlEditor extends MultiPageEditorPart implements IResourceChangeLis @Override public void doSaveAs() { if(getActivePage() == 0){ - updateFieldsFromXml(); - updateXmlFromModel(); + source.updateModelFromXml(); + source.updateXmlFromModel(); }else{ - updateXmlFromModel(); + source.updateXmlFromModel(); } isPageModified=false; - structured.doSaveAs(); + source.doSaveAs(); } /** @@ -419,175 +333,6 @@ public class XmlEditor extends MultiPageEditorPart implements IResourceChangeLis } } - /** - * Is called when the user switches from the source to the textfields-page. - * The xml is read and the model updated with any changes. Then the - * textfields are updated by reading the model. - */ - public void updateFieldsFromXml(){ - - try { - String string = structured.getDocumentProvider().getDocument(structured.getEditorInput()).get(); - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - doc = builder.parse(new InputSource(new StringReader(string))); - } catch (SAXException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (ParserConfigurationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - NodeList nList; - Element node; - String name, developer, date, url, svnurl, desc; - ArrayList<String> tags = new ArrayList<String>(); - - nList = doc.getElementsByTagName("name"); - node = (Element) nList.item(0); - name =node.getFirstChild().getNodeValue(); - - nList = doc.getElementsByTagName("developer"); - node = (Element) nList.item(0); - developer = node.getFirstChild().getNodeValue(); - - nList = doc.getElementsByTagName("date"); - node = (Element) nList.item(0); - date = node.getFirstChild().getNodeValue(); - - nList = doc.getElementsByTagName("url"); - node = (Element) nList.item(0); - url = node.getFirstChild().getNodeValue(); - - nList = doc.getElementsByTagName("svnurl"); - node = (Element) nList.item(0); - svnurl = node.getFirstChild().getNodeValue(); - - nList = doc.getElementsByTagName("description"); - node = (Element) nList.item(0); - desc = node.getFirstChild().getNodeValue(); - - nList = doc.getElementsByTagName("tag"); - for(int i=0; i<nList.getLength(); i++){ - node = (Element) nList.item(i); - tags.add(node.getFirstChild().getNodeValue()); - } - - if(!name.equals(model.getpName())) - model.setpName(name); - if(!developer.equals(model.getpDev())) - model.setpDev(developer); - if(!date.equals(model.getpDate())) - model.setpDate(date); - if(!url.equals(model.getpUrl())) - model.setpUrl(url); - if(!svnurl.equals(model.getpSvnUrl())) - model.setpSvnUrl(svnurl); - if(!desc.equals(model.getpDesc())) - model.setpDesc(desc); - - model.setpTags(tags); - - setFields(); - } - - /** - * Reads the project model and updates the contents of textfields. - */ - public void setFields(){ - projectName.setText(model.getpName()); - developerName.setText(model.getpDev()); - date.setText(model.getpDate()); - url.setText(model.getpUrl()); - svnUrl.setText(model.getpSvnUrl()); - description.setText(model.getpDesc()); - tags.setText(getTagsStringFromModel()); - } - - /** - * Is called when the user switches from the textfields-page to the - * source-page. The model is read and the contents of the xml-file is - * changed to match the model. - */ - public void updateXmlFromModel(){ - - NodeList nList; - Element node; - - try{ - nList = doc.getElementsByTagName("name"); - node = (Element) nList.item(0); - node.setTextContent(model.getpName()); - - nList = doc.getElementsByTagName("developer"); - node = (Element) nList.item(0); - node.setTextContent(model.getpDev()); - - nList = doc.getElementsByTagName("date"); - node = (Element) nList.item(0); - node.setTextContent(model.getpDate()); - - nList = doc.getElementsByTagName("url"); - node = (Element) nList.item(0); - node.setTextContent(model.getpUrl()); - - nList = doc.getElementsByTagName("svnurl"); - node = (Element) nList.item(0); - node.setTextContent(model.getpSvnUrl()); - - nList = doc.getElementsByTagName("description"); - node = (Element) nList.item(0); - node.setTextContent(model.getpDesc()); - - ArrayList<String> tempTags = model.getpTags(); - nList = doc.getElementsByTagName("tags"); - Node oldTags = (Element) nList.item(0); - Node project = node.getParentNode(); - - - doc.normalizeDocument(); - - Node newTags = doc.createElement("tags"); - - for(int i=0; i<tempTags.size(); i++){ - Element el = doc.createElement("tag"); - el.appendChild(doc.createTextNode(tempTags.get(i))); - newTags.appendChild(el); - } - project.replaceChild(newTags, oldTags); - - - }catch(Exception e){ - e.printStackTrace(); - } - - try { - Source source = new DOMSource(doc); - StringWriter stringWriter = new StringWriter(); - Result result = new StreamResult(stringWriter); - TransformerFactory factory2 = TransformerFactory.newInstance(); - Transformer transformer; - transformer = factory2.newTransformer(); - transformer.setOutputProperty(OutputKeys.INDENT, "yes"); - transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); - transformer.setOutputProperty(OutputKeys.STANDALONE, "yes"); - - transformer.transform(source, result); - String str = stringWriter.getBuffer().toString(); - structured.getDocumentProvider().getDocument(structured.getEditorInput()).set(str); - } catch (TransformerConfigurationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (TransformerException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - /** * Marks the editor as dirty if changes are made. */ @@ -603,34 +348,6 @@ public class XmlEditor extends MultiPageEditorPart implements IResourceChangeLis return isPageModified || super.isDirty(); } - /** - * - * Keeps the model updated when changes happen in the textfields. - * - */ - class FieldListener implements ModifyListener{ - - @Override - public void modifyText(ModifyEvent e) { - isDirty = true; - fieldsModified(); - if(e.getSource()==projectName){ - model.setpName(projectName.getText()); - }else if(e.getSource() == developerName){ - model.setpDev(developerName.getText()); - }else if(e.getSource()==date){ - model.setpDate(date.getText()); - }else if(e.getSource()==url){ - model.setpUrl(url.getText()); - }else if(e.getSource()==svnUrl){ - model.setpSvnUrl(svnUrl.getText()); - }else if(e.getSource()==description){ - model.setpDesc(description.getText()); - }else if(e.getSource()==tags) - model.setpTags(getTagsFromFields()); - } - } - /** * Reads the xml, and puts all the tags in an ArrayList<String> * @@ -649,52 +366,11 @@ public class XmlEditor extends MultiPageEditorPart implements IResourceChangeLis return tags; } - /** - * Reads the ArrayList<String> in the model, and constructs a String with - * all the tags separated by commas. - * - */ - private String getTagsStringFromModel(){ - String result=""; - ArrayList<String> tags = model.getpTags(); - for(int i=0; i<tags.size();i++){ - result += tags.get(i); - if(i!=tags.size()-1){ - result += ", "; - } - } - return result; - } - - /** - * Reads the tags-textfield and constructs an ArrayList<String> containing - * all the tags. - * - */ - private ArrayList<String> getTagsFromFields(){ - ArrayList<String> result = new ArrayList<String>(); - String string = tags.getText(); - String tempString=""; - int prevComma=0; - int nextComma=string.indexOf(','); - while(nextComma>=0){ - tempString=string.substring(prevComma, nextComma); - prevComma=nextComma+1; - nextComma = string.indexOf(',', prevComma); - result.add(tempString.trim()); - } - result.add((string.substring(prevComma)).trim()); - return result; - } - - private void fieldsModified(){ + public void fieldsModified(){ boolean wasDirty = isDirty(); isPageModified = true; if(!wasDirty){ firePropertyChange(IEditorPart.PROP_DIRTY); } } - - - }