001 package nl.cwi.sen1.gui.plugin; 002 003 import nl.cwi.sen1.gui.CloseAbortedException; 004 import nl.cwi.sen1.gui.Studio; 005 import nl.cwi.sen1.gui.StudioImplWithPredefinedLayout; 006 import nl.cwi.sen1.gui.StudioWithPredefinedLayout; 007 import nl.cwi.sen1.gui.component.StudioComponent; 008 import nl.cwi.sen1.gui.component.StudioComponentImpl; 009 import nl.cwi.sen1.moduleapi.Factory; 010 import nl.cwi.sen1.moduleapi.types.Attribute; 011 import nl.cwi.sen1.moduleapi.types.AttributeStore; 012 import nl.cwi.sen1.moduleapi.types.TableEntry; 013 import nl.cwi.sen1.moduleapi.types.TableEntryTable; 014 import aterm.ATerm; 015 import aterm.pure.PureFactory; 016 017 public class Moduledetails extends DefaultStudioPlugin implements ModuledetailsTif { 018 private static final String TOOL_NAME = "moduledetails"; 019 020 private ModuledetailsBridge bridge; 021 022 private Factory factory; 023 024 private ModuledetailsPanel panel; 025 026 public String getName() { 027 return TOOL_NAME; 028 } 029 030 public Moduledetails() { 031 } 032 033 public void initStudioPlugin(Studio studio) { 034 factory = Factory.getInstance((PureFactory) studio 035 .getATermFactory()); 036 037 panel = new ModuledetailsPanel(); 038 039 bridge = new ModuledetailsBridge(studio.getATermFactory(), this); 040 bridge.setLockObject(this); 041 042 StudioComponent comp = new StudioComponentImpl("Moduledetails", panel) { 043 public void requestClose() throws CloseAbortedException { 044 throw new CloseAbortedException(); 045 } 046 }; 047 studio.connect(getName(), bridge); 048 ((StudioWithPredefinedLayout) studio).addComponent(comp, 049 StudioImplWithPredefinedLayout.BOTTOM_LEFT); 050 } 051 052 public void recTerminate(ATerm t0) { 053 fireStudioPluginClosed(); 054 } 055 056 public void setDetails(ATerm details) { 057 AttributeStore store = factory.AttributeStoreFromTerm(details); 058 059 while (!store.isEmpty()) { 060 Attribute attribute = (Attribute) store.getFirst(); 061 062 ATerm namespace = attribute.getNamespace(); 063 TableEntryTable table = attribute.getTable(); 064 065 while (!table.isEmpty()) { 066 TableEntry entry = (TableEntry) table.getFirst(); 067 068 ATerm key = entry.getKey(); 069 ATerm value = entry.getValue(); 070 panel.setDetails(namespace.toString(), key.toString(), value.toString()); 071 072 table = (TableEntryTable) table.getNext(); 073 } 074 075 store = (AttributeStore) store.getNext(); 076 } 077 } 078 }