1 19 package org.netbeans.modules.xml.axi.impl; 20 21 import java.io.IOException ; 22 import javax.swing.event.UndoableEditListener ; 23 import org.netbeans.modules.xml.axi.AXIModel; 24 import org.netbeans.modules.xml.axi.SchemaGeneratorFactory; 25 import org.netbeans.modules.xml.schema.model.SchemaModel; 26 import org.netbeans.modules.xml.xam.Model; 27 import org.netbeans.modules.xml.xam.ModelAccess; 28 29 34 public class ModelAccessImpl extends ModelAccess { 35 36 39 public ModelAccessImpl(AXIModel model) { 40 this.model = (AXIModelImpl)model; 41 } 42 43 public void addUndoableEditListener(UndoableEditListener listener) { 44 model.addUndoableEditListener(listener); 45 } 46 47 public void removeUndoableEditListener(UndoableEditListener listener) { 48 model.removeUndoableEditListener(listener); 49 } 50 51 public void prepareForUndoRedo() { 52 } 53 54 public void finishUndoRedo() { 55 } 56 57 private SchemaModel getSchemaModel() { 58 return model.getSchemaModel(); 59 } 60 61 public Model.State sync() throws IOException { 62 model.buildReferenceableCache(); 64 65 if(!model.validate()) { 67 setAutoSync(true); 68 return Model.State.NOT_WELL_FORMED; 69 } 70 71 if(!model.isAXIDocumentInitialized()) { 74 model.initializeAXIDocument(); 75 setAutoSync(true); 76 return Model.State.VALID; 77 } 78 79 if(!model.doSync()) { 80 return Model.State.NOT_SYNCED; 81 } 82 83 return Model.State.VALID; 85 } 86 87 public void flush() { 88 try { 89 SchemaGeneratorFactory sgf = SchemaGeneratorFactory.getDefault(); 90 sgf.updateSchema(model.getSchemaModel(), model.getSchemaDesignPattern()); 91 } catch (Exception ex) { 92 throw new IllegalArgumentException ("Exception during flush: ",ex); } finally { 94 model.getPropertyChangeListener().clearEvents(); 95 } 96 } 97 98 102 private long dirtyTimeMillis = 0; 103 public long dirtyIntervalMillis() { 104 if (dirtyTimeMillis == 0) return 0; 105 return System.currentTimeMillis() - dirtyTimeMillis; 106 } 107 108 public void setDirty() { 109 dirtyTimeMillis = System.currentTimeMillis(); 110 } 111 112 public void unsetDirty() { 113 dirtyTimeMillis = 0; 114 } 115 116 private AXIModelImpl model; 117 } 118 | Popular Tags |