1 19 20 package org.netbeans.modules.xml.xam.ui.customizer; 21 22 import java.io.IOException ; 23 import java.util.Iterator ; 24 import org.netbeans.modules.xml.xam.Component; 25 import org.netbeans.modules.xml.xam.Model; 26 import org.netbeans.modules.xml.xam.Nameable; 27 import org.netbeans.modules.xml.xam.ui.XAMUtils; 28 29 35 public abstract class AbstractComponentCustomizer<T extends Component> 36 extends AbstractCustomizer { 37 private transient T component; 38 private transient MessageDisplayer messageDisplayer; 39 44 public AbstractComponentCustomizer(T component) { 45 this.component = component; 46 messageDisplayer = new MessagePanel(); 47 messageDisplayer.clear(); 48 } 49 50 public boolean isEditable() { 51 return XAMUtils.isWritable(component.getModel()); 52 } 53 54 57 public void apply() throws IOException { 58 Model model = component.getModel(); 59 boolean startTransaction = model != null && !model.isIntransaction(); 62 if (startTransaction) { 63 model.startTransaction(); 64 } 65 try { 66 applyChanges(); 67 setSaveEnabled(false); 68 setResetEnabled(false); 69 } finally { 70 if (startTransaction) { 71 model.endTransaction(); 72 } 73 } 74 } 75 76 81 protected T getModelComponent() { 82 return component; 83 } 84 85 93 protected boolean isNameValid(String name) { 94 T comp = getModelComponent(); 95 if (!(comp instanceof Nameable)) { 96 return true; 97 } 98 if (name == null || name.trim().length() == 0) { 99 return false; 100 } 101 Iterator iter = comp.getParent().getChildren().iterator(); 102 while (iter.hasNext()) { 103 Object child = iter.next(); 104 if (child instanceof Nameable) { 105 Nameable named = (Nameable) child; 106 if (name.equals(named.getName())) { 107 return false; 108 } 109 } 110 } 111 return true; 112 } 113 114 protected abstract void applyChanges() throws IOException ; 115 116 protected MessageDisplayer getMessageDisplayer() 117 { 118 return messageDisplayer; 119 } 120 } 121 | Popular Tags |