1 30 package com.genimen.djeneric.tools.specifier.base; 31 32 import java.io.InputStream ; 33 34 import javax.swing.JPanel ; 35 36 import com.genimen.djeneric.repository.exceptions.DjenericException; 37 import com.genimen.djeneric.structure.EditorDefinition; 38 import com.genimen.djeneric.structure.ResourceDefinition; 39 import com.genimen.djeneric.tools.specifier.interfaces.SpecifierPanel; 40 import com.genimen.djeneric.tools.specifier.interfaces.SpecifierPanelContainer; 41 42 public abstract class BasePanel extends JPanel implements SpecifierPanel 43 { 44 47 abstract protected void cleanup() throws DjenericException; 48 49 private SpecifierPanelContainer _panelContainer; 50 51 protected SpecifierPanelContainer getSpecifierPanelContainer() 52 { 53 return _panelContainer; 54 } 55 56 public void setSpecifierPanelContainer(SpecifierPanelContainer container) 57 { 58 _panelContainer = container; 59 } 60 61 public void setStatusMessage(String msg) 62 { 63 _panelContainer.setStatusMessage(msg, true); 64 } 65 66 public void setStatusMessage(Throwable t) 67 { 68 _panelContainer.setStatusMessage(t); 69 } 70 71 public void setStatusMessage(String msg, boolean isInformative) 72 { 73 _panelContainer.setStatusMessage(msg, isInformative); 74 } 75 76 public void setStatusMessageNow(String msg, boolean isInformative) 77 { 78 _panelContainer.setStatusMessageNow(msg, isInformative); 79 } 80 81 public ResourceDefinition getResourceDefinition(String name) 82 { 83 return _panelContainer.getResourceDefinition(name); 84 } 85 86 public InputStream getResourceAsStream(String name) 87 { 88 return _panelContainer.getResourceAsStream(name); 89 } 90 91 public Class loadClass(String name) throws ClassNotFoundException 92 { 93 return _panelContainer.loadClass(name); 94 } 95 96 public EditorDefinition getEditorDefinition(String editorName) 97 { 98 return _panelContainer.getEditorDefinition(editorName); 99 } 100 101 public boolean editorExists(String editorName) 102 { 103 return _panelContainer.getEditorDefinition(editorName) != null; 104 } 105 106 public boolean canClose() 107 { 108 return true; 109 } 110 111 public boolean close() 112 { 113 try 114 { 115 cleanup(); 116 removeFromContainer(); 117 return true; 118 } 119 catch (DjenericException x) 120 { 121 setStatusMessage(x.getMessage(), false); 122 return false; 123 } 124 } 125 126 public void removeFromContainer() 127 { 128 if (getSpecifierPanelContainer() == null) 129 { 130 System.err.println("Internal error: BasePanel.setSpecifierPanelContainer() not called. " 131 + "Don't know how to remove panel"); 132 } 133 else getSpecifierPanelContainer().notifyClosed(this); 134 } 135 136 } | Popular Tags |