KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > terracotta > dso > editors > ConfigurationEditor


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package org.terracotta.dso.editors;
5
6 import org.apache.xmlbeans.XmlOptions;
7 import org.dijon.ScrollPane;
8 import org.eclipse.core.resources.IFile;
9 import org.eclipse.core.resources.IMarker;
10 import org.eclipse.core.resources.IProject;
11 import org.eclipse.core.resources.IResource;
12 import org.eclipse.core.resources.IResourceChangeEvent;
13 import org.eclipse.core.resources.IResourceChangeListener;
14 import org.eclipse.core.resources.IResourceDelta;
15 import org.eclipse.core.resources.IResourceDeltaVisitor;
16 import org.eclipse.core.resources.IWorkspace;
17 import org.eclipse.core.resources.ResourcesPlugin;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.runtime.IPath;
20 import org.eclipse.core.runtime.IProgressMonitor;
21 import org.eclipse.core.runtime.IStatus;
22 import org.eclipse.jface.dialogs.ErrorDialog;
23 import org.eclipse.jface.dialogs.IMessageProvider;
24 import org.eclipse.jface.dialogs.MessageDialog;
25 import org.eclipse.jface.text.DocumentEvent;
26 import org.eclipse.jface.text.IDocument;
27 import org.eclipse.jface.text.IDocumentListener;
28 import org.eclipse.jface.text.ITextInputListener;
29 import org.eclipse.jface.window.Window;
30 import org.eclipse.swt.SWT;
31 import org.eclipse.swt.awt.SWT_AWT;
32 import org.eclipse.swt.widgets.Composite;
33 import org.eclipse.swt.widgets.Display;
34 import org.eclipse.swt.widgets.Shell;
35 import org.eclipse.ui.IEditorInput;
36 import org.eclipse.ui.IEditorSite;
37 import org.eclipse.ui.IFileEditorInput;
38 import org.eclipse.ui.PartInitException;
39 import org.eclipse.ui.PlatformUI;
40 import org.eclipse.ui.dialogs.SaveAsDialog;
41 import org.eclipse.ui.ide.IDE;
42 import org.eclipse.ui.ide.IGotoMarker;
43 import org.eclipse.ui.part.FileEditorInput;
44 import org.eclipse.ui.part.MultiPageEditorPart;
45 import org.eclipse.ui.texteditor.IDocumentProvider;
46 import org.eclipse.ui.texteditor.IElementStateListener;
47 import org.terracotta.dso.ConfigurationHelper;
48 import org.terracotta.dso.JavaSetupParticipant;
49 import org.terracotta.dso.Messages;
50 import org.terracotta.dso.TcPlugin;
51 import org.terracotta.dso.decorator.AdaptedModuleDecorator;
52 import org.terracotta.dso.decorator.AdaptedPackageFragmentDecorator;
53 import org.terracotta.dso.decorator.AdaptedTypeDecorator;
54 import org.terracotta.dso.decorator.AutolockedDecorator;
55 import org.terracotta.dso.decorator.DistributedMethodDecorator;
56 import org.terracotta.dso.decorator.ExcludedModuleDecorator;
57 import org.terracotta.dso.decorator.ExcludedTypeDecorator;
58 import org.terracotta.dso.decorator.NameLockedDecorator;
59 import org.terracotta.dso.decorator.RootDecorator;
60 import org.terracotta.dso.decorator.TransientDecorator;
61 import org.terracotta.dso.editors.xml.XMLEditor;
62
63 import com.terracottatech.config.Application;
64 import com.terracottatech.config.TcConfigDocument;
65 import com.terracottatech.config.TcConfigDocument.TcConfig;
66
67 import java.awt.Frame JavaDoc;
68 import java.awt.event.ActionEvent JavaDoc;
69 import java.awt.event.ActionListener JavaDoc;
70 import java.io.IOException JavaDoc;
71 import java.text.MessageFormat JavaDoc;
72
73 import javax.swing.JRootPane JavaDoc;
74 import javax.swing.SwingUtilities JavaDoc;
75 import javax.swing.Timer JavaDoc;
76 import javax.swing.UIManager JavaDoc;
77
78 public class ConfigurationEditor extends MultiPageEditorPart
79   implements IResourceChangeListener,
80              IGotoMarker
81 {
82   private IProject m_project;
83   private Application m_application;
84   private DsoApplicationPanel m_dsoAppPanel;
85   private ServersPanel m_serversPanel;
86   private ClientsPanel m_clientsPanel;
87   private XMLEditor m_xmlEditor;
88   private int m_xmlEditorPageIndex;
89   private ResourceDeltaVisitor m_resourceDeltaVisitor;
90   private boolean m_haveActiveConfig;
91   private DocumentListener m_docListener;
92   private ElementStateListener m_elementStateListener;
93   private TextInputListener m_textInputListener;
94   private Timer JavaDoc m_parseTimer;
95   
96   static {
97     try {
98       java.lang.System.setProperty("sun.awt.noerasebackground", "true");
99       java.lang.System.setProperty("swing.volatileImageBufferEnabled", "false");
100     } catch(Throwable JavaDoc t) {/**/}
101   }
102   
103   public ConfigurationEditor() {
104     super();
105     
106     m_docListener = new DocumentListener();
107     m_elementStateListener = new ElementStateListener();
108     m_textInputListener = new TextInputListener();
109     m_parseTimer = new Timer JavaDoc(2000, new ParseTimerAction());
110     
111     m_parseTimer.setRepeats(false);
112   }
113     
114   private Composite createComposite() {
115     return new Composite(getContainer(), SWT.EMBEDDED);
116   }
117   
118   void createDsoApplicationPage(int pageIndex) {
119     final Composite composite = createComposite();
120     final Frame JavaDoc frame = SWT_AWT.new_Frame(composite);
121     JRootPane JavaDoc rootPane = new JRootPane JavaDoc();
122
123     rootPane.setBackground(UIManager.getColor("control"));
124     rootPane.setOpaque(true);
125     frame.add(rootPane);
126     ScrollPane scroller = new ScrollPane(m_dsoAppPanel = new DsoApplicationPanel());
127     rootPane.getContentPane().add(scroller);
128     m_dsoAppPanel.setup(m_project);
129     m_dsoAppPanel.setVisible(true);
130
131     addPage(pageIndex, composite);
132     setPageText(pageIndex, "DSO config");
133   }
134
135   public DsoApplicationPanel getDsoApplicationPanel() {
136     return m_dsoAppPanel;
137   }
138   
139   protected void pageChange(final int newPageIndex) {
140     if(newPageIndex != 0) {
141       if(m_project != null && m_project.isOpen()) {
142         TcPlugin plugin = TcPlugin.getDefault();
143         TcConfig config = plugin.getConfiguration(m_project);
144        
145         if(config == TcPlugin.BAD_CONFIG) {
146           Display.getDefault().syncExec(new Runnable JavaDoc() {
147             public void run() {
148               getControl(newPageIndex).setVisible(false);
149
150               Shell shell = Display.getDefault().getActiveShell();
151               String JavaDoc title = "Terracotta Config Editor";
152               String JavaDoc msg = "The source page has errors. The other pages cannot be\nused until these errors are resolved.";
153               
154               MessageDialog.openWarning(shell, title, msg);
155             }
156           });
157           setActivePage(0);
158         }
159       }
160     }
161   }
162   
163   public void showDsoApplicationPanel() {
164     setActivePage(0);
165   }
166   
167   void createServersPage(int pageIndex) {
168     final Composite composite = createComposite();
169     final Frame JavaDoc frame = SWT_AWT.new_Frame(composite);
170     JRootPane JavaDoc rootPane = new JRootPane JavaDoc();
171
172     rootPane.setBackground(UIManager.getColor("control"));
173     rootPane.setOpaque(true);
174     frame.add(rootPane);
175     ScrollPane scroller = new ScrollPane(m_serversPanel = new ServersPanel());
176     rootPane.getContentPane().add(scroller);
177     m_serversPanel.setup(m_project);
178     m_serversPanel.setVisible(true);
179
180     addPage(pageIndex, composite);
181     setPageText(pageIndex, "Servers config");
182   }
183     
184   void createClientPage(int pageIndex) {
185     final Composite composite = createComposite();
186     final Frame JavaDoc frame = SWT_AWT.new_Frame(composite);
187     JRootPane JavaDoc rootPane = new JRootPane JavaDoc();
188
189     frame.setBackground(UIManager.getColor("control"));
190     rootPane.setOpaque(true);
191     frame.add(rootPane);
192     ScrollPane scroller = new ScrollPane(m_clientsPanel = new ClientsPanel());
193     rootPane.getContentPane().add(scroller);
194     m_clientsPanel.setup(m_project);
195     m_clientsPanel.setVisible(true);
196
197     addPage(pageIndex, composite);
198     setPageText(pageIndex, "Clients config");
199   }
200     
201   void createXMLEditorPage(int pageIndex) {
202     try {
203       IEditorInput input = getEditorInput();
204
205       addPage(m_xmlEditorPageIndex = pageIndex, m_xmlEditor = new XMLEditor(), input);
206       setPageText(m_xmlEditorPageIndex, m_xmlEditor.getTitle());
207
208       m_xmlEditor.addTextInputListener(m_textInputListener);
209       m_xmlEditor.getDocument().addDocumentListener(m_docListener);
210       m_xmlEditor.getDocumentProvider().addElementStateListener(m_elementStateListener);
211     }
212     catch(PartInitException e) {
213       ErrorDialog.openError(
214         getSite().getShell(),
215         "Error creating nested text editor",
216         null,
217         e.getStatus());
218     }
219   }
220   
221   public boolean isActiveConfig() {
222     TcPlugin plugin = TcPlugin.getDefault();
223     IFile configFile = plugin.getConfigurationFile(m_project);
224     IFileEditorInput fileEditorInput = (FileEditorInput)getEditorInput();
225     IFile file = fileEditorInput.getFile();
226     
227     return file != null && file.equals(configFile);
228   }
229   
230   boolean haveActiveConfig() {
231     return m_haveActiveConfig;
232   }
233   
234   protected void createPages() {
235     createXMLEditorPage(0);
236
237     if(haveActiveConfig()) {
238       createDsoApplicationPage(1);
239       createServersPage(2);
240       createClientPage(3);
241
242       ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
243     }
244   }
245
246   public void dispose() {
247     ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
248     super.dispose();
249   }
250  
251   public void doSave(IProgressMonitor monitor) {
252     m_xmlEditor.doSave(monitor);
253   }
254
255   public void doSaveAs() {
256     performSaveAs(null);
257   }
258
259   protected void performSaveAs(IProgressMonitor progressMonitor) {
260     Shell shell = getSite().getShell();
261     IEditorInput input = getEditorInput();
262     SaveAsDialog dialog = new SaveAsDialog(shell);
263     IFile original = null;
264     
265     if(input instanceof IFileEditorInput) {
266       if((original = ((IFileEditorInput)input).getFile()) != null) {
267         dialog.setOriginalFile(original);
268       }
269     }
270
271     dialog.create();
272
273     IDocumentProvider provider = m_xmlEditor.getDocumentProvider();
274     if(provider == null) {
275       // editor has programmatically been closed while the dialog was open
276
return;
277     }
278
279     if(provider.isDeleted(input) && original != null) {
280       String JavaDoc message = MessageFormat.format(Messages.Editor_warning_save_delete,
281                                             new Object JavaDoc[] {original.getName()});
282       
283       dialog.setErrorMessage(null);
284       dialog.setMessage(message, IMessageProvider.WARNING);
285     }
286     
287     if(dialog.open() == Window.CANCEL) {
288       if(progressMonitor != null) {
289         progressMonitor.setCanceled(true);
290       }
291       return;
292     }
293
294     IPath filePath = dialog.getResult();
295     if(filePath == null) {
296       if(progressMonitor != null) {
297         progressMonitor.setCanceled(true);
298       }
299       return;
300     }
301
302     IWorkspace workspace = ResourcesPlugin.getWorkspace();
303     IFile file = workspace.getRoot().getFile(filePath);
304     final IEditorInput newInput = new FileEditorInput(file);
305     boolean success = false;
306
307     try {
308       provider.aboutToChange(newInput);
309       provider.saveDocument(progressMonitor,
310                             newInput,
311                             provider.getDocument(input),
312                             true);
313       success = true;
314       clearDirty();
315     } catch(CoreException ce) {
316       IStatus status = ce.getStatus();
317       
318       if(status == null || status.getSeverity() != IStatus.CANCEL) {
319         String JavaDoc title = Messages.Editor_error_save_title;
320         String JavaDoc msg = MessageFormat.format(Messages.Editor_error_save_message,
321                                             new Object JavaDoc[] {ce.getMessage()});
322
323         if(status != null) {
324           switch(status.getSeverity()) {
325             case IStatus.INFO:
326               MessageDialog.openInformation(shell, title, msg);
327               break;
328             case IStatus.WARNING:
329               MessageDialog.openWarning(shell, title, msg);
330               break;
331             default:
332               MessageDialog.openError(shell, title, msg);
333           }
334         }
335         else {
336           MessageDialog.openError(shell, title, msg);
337         }
338       }
339     } finally {
340       provider.changed(newInput);
341       if(success) {
342         setInput(newInput);
343       }
344     }
345
346     if(progressMonitor != null) {
347       progressMonitor.setCanceled(!success);
348     }
349   }
350   
351   public void gotoMarker(IMarker marker) {
352     setActivePage(0);
353     IDE.gotoMarker(getEditor(0), marker);
354   }
355
356   public void newInputFile(final IFile file) {
357     if(file != null && file.exists()) {
358       final FileEditorInput input = new FileEditorInput(file);
359       
360       setInput(input);
361
362       m_project = file.getProject();
363
364       if(haveActiveConfig()) {
365         if(getPageCount() == 1) {
366           createDsoApplicationPage(1);
367           createServersPage(2);
368           createClientPage(3);
369         }
370         ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
371         initPanels();
372       } else {
373         ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
374         for(int i = getPageCount()-1; i > 0; i--) {
375           removePage(i);
376         }
377       }
378       
379       syncExec(new Runnable JavaDoc() {
380         public void run() {
381           m_xmlEditor.setInput(input);
382           String JavaDoc name = file.getName();
383           setPartName(name);
384           setPageText(m_xmlEditorPageIndex, name);
385         }
386       });
387     }
388   }
389   
390   private void syncExec(Runnable JavaDoc runner) {
391     getSite().getShell().getDisplay().syncExec(runner);
392   }
393   
394   private void asyncExec(Runnable JavaDoc runner) {
395     getSite().getShell().getDisplay().asyncExec(runner);
396   }
397
398   public void init(IEditorSite site, IEditorInput editorInput)
399     throws PartInitException
400   {
401     if(!(editorInput instanceof IFileEditorInput)) {
402       throw new PartInitException("Invalid Input: Must be IFileEditorInput");
403     }
404    
405     IFileEditorInput fileEditorInput = (IFileEditorInput)editorInput;
406     IFile file = fileEditorInput.getFile();
407     IProject project = file.getProject();
408     
409     if(!project.exists()) {
410       String JavaDoc msg = "Project '"+project.getName()+"' does not exist";
411
412       ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
413       throw new PartInitException(msg);
414     }
415     
416     if(!project.isOpen()) {
417       String JavaDoc msg = "Project '"+project.getName()+"' is not open";
418
419       ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
420       throw new PartInitException(msg);
421     }
422
423     m_project = project;
424     super.init(site, editorInput);
425
426     setPartName(file.getName());
427   }
428   
429   protected void setInput(IEditorInput input) {
430     super.setInput(input);
431     m_haveActiveConfig = isActiveConfig();
432   }
433
434   public boolean isSaveAsAllowed() {
435     return true;
436   }
437   
438   private ResourceDeltaVisitor getResourceDeltaVisitor() {
439     if(m_resourceDeltaVisitor == null) {
440       m_resourceDeltaVisitor = new ResourceDeltaVisitor();
441     }
442     return m_resourceDeltaVisitor;
443   }
444   
445   class ResourceDeltaVisitor implements IResourceDeltaVisitor {
446     public boolean visit(IResourceDelta delta) {
447       if(PlatformUI.getWorkbench().isClosing()) {
448         return false;
449       }
450       
451       if(delta.getKind() == IResourceDelta.CHANGED) {
452         TcPlugin plugin = TcPlugin.getDefault();
453         IResource res = delta.getResource();
454           
455         if(res instanceof IFile) {
456           IProject project = res.getProject();
457           int flags = delta.getFlags();
458           
459           if(project != null && (flags & IResourceDelta.CONTENT) != 0) {
460             if((flags & IResourceDelta.MARKERS) != 0) {
461               return false;
462             }
463             IFile configFile = plugin.getConfigurationFile(project);
464             
465             if(configFile != null && configFile.equals(res)) {
466               plugin.reloadConfiguration(m_project);
467               initPanels();
468               clearDirty();
469
470               return false;
471             }
472           }
473         }
474       }
475       
476       return true;
477     }
478   }
479
480   /**
481    * Ensures that the config has an Application element.
482    */

483   private void ensureRequiredConfigElements() {
484     if(m_project != null && m_project.isOpen()) {
485       TcConfig config = TcPlugin.getDefault().getConfiguration(m_project);
486     
487       if(config != null) {
488         m_application = config.getApplication();
489       
490         if(m_application == null) {
491           m_application = config.addNewApplication();
492           m_application.addNewDso().addNewInstrumentedClasses();
493         }
494       }
495     }
496   }
497
498   public void initPanels() {
499     try {
500       SwingUtilities.invokeAndWait(new Runnable JavaDoc () {
501         public void run() {
502           if(m_project != null && m_project.isOpen()) {
503             enablePanels();
504             ensureRequiredConfigElements();
505           
506             m_dsoAppPanel.setup(m_project);
507             m_serversPanel.setup(m_project);
508             m_clientsPanel.setup(m_project);
509           }
510           else {
511             disablePanels();
512           }
513         }
514       });
515     } catch(Exception JavaDoc e) {
516       e.printStackTrace();
517     }
518   }
519   
520   public void updateInstrumentedClassesPanel() {
521     syncXmlDocument();
522     try {
523       SwingUtilities.invokeAndWait(new Runnable JavaDoc () {
524         public void run() {
525           m_dsoAppPanel.updateInstrumentedClassesPanel();
526         }
527       });
528     } catch(Exception JavaDoc e) {
529       e.printStackTrace();
530     }
531     TcPlugin.getDefault().updateDecorators(
532       new String JavaDoc[] {
533         AdaptedModuleDecorator.DECORATOR_ID,
534         AdaptedTypeDecorator.DECORATOR_ID,
535         AdaptedPackageFragmentDecorator.DECORATOR_ID,
536         ExcludedTypeDecorator.DECORATOR_ID,
537         ExcludedModuleDecorator.DECORATOR_ID});
538   }
539
540   public void updateTransientsPanel() {
541     syncXmlDocument();
542     try {
543       SwingUtilities.invokeAndWait(new Runnable JavaDoc () {
544         public void run() {
545           m_dsoAppPanel.updateTransientsPanel();
546         }
547       });
548     } catch(Exception JavaDoc e) {
549       e.printStackTrace();
550     }
551     TcPlugin.getDefault().updateDecorator(TransientDecorator.DECORATOR_ID);
552   }
553   
554   public void updateRootsPanel() {
555     syncXmlDocument();
556     try {
557       SwingUtilities.invokeAndWait(new Runnable JavaDoc () {
558         public void run() {
559           m_dsoAppPanel.updateRootsPanel();
560         }
561       });
562     } catch(Exception JavaDoc e) {
563       e.printStackTrace();
564     }
565     TcPlugin.getDefault().updateDecorator(RootDecorator.DECORATOR_ID);
566   }
567
568   public void updateDistributedMethodsPanel() {
569     try {
570       SwingUtilities.invokeAndWait(new Runnable JavaDoc () {
571         public void run() {
572           m_dsoAppPanel.updateDistributedMethodsPanel();
573         }
574       });
575     } catch(Exception JavaDoc e) {
576       e.printStackTrace();
577     }
578     TcPlugin.getDefault().updateDecorator(DistributedMethodDecorator.DECORATOR_ID);
579   }
580
581   public void updateLocksPanel() {
582     try {
583       SwingUtilities.invokeAndWait(new Runnable JavaDoc () {
584         public void run() {
585           m_dsoAppPanel.updateLocksPanel();
586         }
587       });
588     } catch(Exception JavaDoc e) {
589       e.printStackTrace();
590     }
591     TcPlugin.getDefault().updateDecorators(
592       new String JavaDoc[] {
593         NameLockedDecorator.DECORATOR_ID,
594         AutolockedDecorator.DECORATOR_ID});
595   }
596
597   public void updateBootClassesPanel() {
598     try {
599       SwingUtilities.invokeAndWait(new Runnable JavaDoc () {
600         public void run() {
601           m_dsoAppPanel.updateBootClassesPanel();
602         }
603       });
604     } catch(Exception JavaDoc e) {
605       e.printStackTrace();
606     }
607   }
608
609   private void disablePanels() {
610     m_dsoAppPanel.setEnabled(false);
611     m_serversPanel.setEnabled(false);
612     m_clientsPanel.setEnabled(false);
613   }
614   
615   private void enablePanels() {
616     m_dsoAppPanel.setEnabled(true);
617     m_serversPanel.setEnabled(true);
618     m_clientsPanel.setEnabled(true);
619   }
620   
621   public void closeEditor() {
622     getSite().getPage().closeEditor(this, true);
623   }
624   
625   public void resourceChanged(final IResourceChangeEvent event){
626     switch(event.getType()) {
627       case IResourceChangeEvent.PRE_DELETE:
628       case IResourceChangeEvent.PRE_CLOSE: {
629         asyncExec(new Runnable JavaDoc() {
630           public void run(){
631             if(m_project.equals(event.getResource())) {
632               ConfigurationEditor.this.closeEditor();
633             }
634           }
635         });
636         break;
637       }
638       case IResourceChangeEvent.POST_CHANGE: {
639         asyncExec(new Runnable JavaDoc() {
640           public void run(){
641             try {
642               event.getDelta().accept(getResourceDeltaVisitor());
643             } catch(CoreException ce) {
644               ce.printStackTrace();
645             }
646           }
647         });
648         break;
649       }
650     }
651   }
652
653   public void syncXmlDocument() {
654     TcPlugin plugin = TcPlugin.getDefault();
655     IDocument doc = m_xmlEditor.getDocument();
656     XmlOptions opts = plugin.getXmlOptions();
657     
658     TcConfig config = plugin.getConfiguration(m_project);
659
660     if(config != null) {
661       TcConfigDocument configDoc = TcConfigDocument.Factory.newInstance();
662       
663       configDoc.setTcConfig(config);
664       doc.removeDocumentListener(m_docListener);
665       doc.set(configDoc.xmlText(opts));
666       doc.addDocumentListener(m_docListener);
667     }
668   }
669
670   public synchronized void syncXmlModel() {
671     TcPlugin plugin = TcPlugin.getDefault();
672     IDocument doc = m_xmlEditor.getDocument();
673     String JavaDoc xmlText = doc.get();
674     
675     try {
676       plugin.setConfigurationFromString(m_project, xmlText);
677       initPanels();
678     } catch(IOException JavaDoc ioe) {
679       disablePanels();
680     }
681   }
682
683   /**
684    * This gets invokes by our sub-components when they've modified the model.
685    */

686   public synchronized void setDirty() {
687     syncXmlDocument();
688     internalSetDirty(Boolean.TRUE);
689
690     TcPlugin plugin = TcPlugin.getDefault();
691     plugin.getConfigurationHelper(m_project).validateAll();
692     JavaSetupParticipant.inspectAll();
693     plugin.updateDecorators();
694     plugin.fireConfigurationChange(m_project);
695   }
696
697   private void clearDirty() {
698     internalSetDirty(Boolean.FALSE);
699   }
700   
701   private void internalSetDirty(Boolean JavaDoc isDirty) {
702     TcPlugin.getDefault().setConfigurationFileDirty(m_project, isDirty);
703     firePropertyChange(PROP_DIRTY);
704   }
705   
706   public boolean isDirty() {
707     if(m_project != null && haveActiveConfig()) {
708       return m_project.isOpen() && TcPlugin.getDefault().isConfigurationFileDirty(m_project);
709     } else {
710       return super.isDirty();
711     }
712   }
713   
714   public void modelChanged() {
715     syncXmlDocument();
716     internalSetDirty(Boolean.TRUE);
717   }
718   
719   public IDocument getDocument() {
720     return m_xmlEditor.getDocument();
721   }
722   
723   class TextInputListener implements ITextInputListener {
724     public void inputDocumentAboutToBeChanged(
725       IDocument oldInput,
726       IDocument newInput) {/**/}
727     
728     public void inputDocumentChanged(
729       IDocument oldInput,
730       IDocument newInput)
731     {
732       if(oldInput != null) {
733         oldInput.removeDocumentListener(m_docListener);
734       }
735       if(newInput != null) {
736         newInput.addDocumentListener(m_docListener);
737       }
738     }
739   }
740   
741   class ElementStateListener implements IElementStateListener {
742     public void elementContentAboutToBeReplaced(Object JavaDoc element) {
743       m_xmlEditor.getDocument().removeDocumentListener(m_docListener);
744     }
745
746     public void elementContentReplaced(Object JavaDoc element) {
747       m_xmlEditor.getDocument().addDocumentListener(m_docListener);
748     }
749
750     public void elementDeleted(Object JavaDoc element) {/**/}
751     public void elementMoved(Object JavaDoc originalElement, Object JavaDoc movedElement) {/**/}
752     public void elementDirtyStateChanged(Object JavaDoc element, boolean isDirty) {/**/}
753   }
754   
755   class DocumentListener implements IDocumentListener {
756     public void documentAboutToBeChanged(DocumentEvent event) {/**/}
757     
758     public void documentChanged(DocumentEvent event) {
759       if(haveActiveConfig()) m_parseTimer.stop();
760       internalSetDirty(Boolean.TRUE);
761       if(haveActiveConfig()) m_parseTimer.start();
762     }
763   }
764   
765   class ParseTimerAction implements ActionListener JavaDoc {
766     public void actionPerformed(ActionEvent JavaDoc ae) {
767       asyncExec(new Runnable JavaDoc() {
768         public void run(){
769           syncXmlModel();
770         }
771       });
772     }
773   }
774   
775   public void applyProblemToText(String JavaDoc text, String JavaDoc msg, String JavaDoc markerType) {
776     TcPlugin plugin = TcPlugin.getDefault();
777     IDocument doc = m_xmlEditor.getDocument();
778     ConfigurationHelper configHelper = plugin.getConfigurationHelper(m_project);
779     
780     configHelper.applyProblemToText(doc, text, msg, markerType);
781   }
782 }
783
Popular Tags