tinydtview.java
来自「plugin for eclipse」· Java 代码 · 共 482 行 · 第 1/2 页
JAVA
482 行
public static TinydtView getTinydtView()
{
return tinydtView;
}
public TinydtView()
{
tinydtView = this;
tree = buildTree();
}
public void createPartControl(Composite parent)
{
imageRegistry = new ImageRegistry(parent.getDisplay());
imageRegistry.put("config", TinydtPlugin.imageDescriptorFromPlugin("isis.tinydt", "icons/config.gif"));
imageRegistry.put("module", TinydtPlugin.imageDescriptorFromPlugin("isis.tinydt", "icons/module.gif"));
imageRegistry
.put("declaration", TinydtPlugin.imageDescriptorFromPlugin("isis.tinydt", "icons/declaration.gif"));
imageRegistry.put("provided_interface", TinydtPlugin.imageDescriptorFromPlugin("isis.tinydt",
"icons/provided.gif"));
imageRegistry.put("used_interface", TinydtPlugin.imageDescriptorFromPlugin("isis.tinydt", "icons/used.gif"));
viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
//drillDownAdapter = new DrillDownAdapter(viewer);
viewer.setContentProvider(new ViewContentProvider());
viewer.setLabelProvider(new ViewLabelProvider());
viewer.setInput(tree);
hookDoubleClickAction();
}
private void hookDoubleClickAction()
{
viewer.addDoubleClickListener(new IDoubleClickListener()
{
public void doubleClick(DoubleClickEvent event)
{
try
{
Object element = ((IStructuredSelection) event.getSelection()).getFirstElement();
if(element instanceof ConfigItem)
{
Configuration config = ((ConfigItem) element).config;
Utils.openEditor(Utils.removeDotFromFileName(config.getConfigurationFile().getFileName()));
}
else if(element instanceof ModuleItem)
{
Module module = ((ModuleItem) element).module;
Utils.openEditor(Utils.removeDotFromFileName(module.getModuleFile().getFileName()));
}
else if(element instanceof InterfaceItem)
{
Interface interf = ((InterfaceItem) element).port.getInterface();
Utils.openEditor(Utils.removeDotFromFileName(interf.getInterfaceFile().getFileName()));
}
else if(element instanceof DeclarationItem)
{
Declaration decl = ((DeclarationItem) element).decl;
//System.out.println("decl="+decl);
//System.out.println(decl.getParent());
IWorkbenchPage page = TinydtPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow()
.getActivePage();
IFile f = null;
if(decl.getParent() instanceof ModuleImplementation)
{
ModuleImplementation moduleImpl = (ModuleImplementation) decl.getParent();
f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(
new Path(Utils.removeDotFromFileName(moduleImpl.getModule().getModuleFile().getFileName())));
}
if(decl.getParent() instanceof Interface)
{
Interface interf = (Interface) decl.getParent();
f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(
new Path(Utils.removeDotFromFileName(interf.getInterfaceFile().getFileName())));
}
if(f != null)
{
NesCEditor e = (NesCEditor) IDE.openEditor(page, f);
TNode n = null;
if(decl.getNameNode() == null)
n = decl.getDefNode();
else
n = decl.getNameNode();
e.getTextEditor().setSelection(n.getLine() - 1, n.getColumn() - 1, n.getLocalTokenLength());
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
});
}
public void setFocus()
{
viewer.getControl().setFocus();
}
private void buildInterface(InterfacePort port, BaseItem parent)
{
InterfaceItem interfaceItem = new InterfaceItem(port, parent);
Iterator it = interfaceItem.port.getInterface().getFunctionDeclarations().iterator();
while(it.hasNext())
{
Declaration d = (Declaration) it.next();
DeclarationItem declItem = new DeclarationItem(d, interfaceItem);
}
}
private void buildConfig(Configuration config, BaseItem parent, int level)
{
ConfigItem configItem = new ConfigItem(config, parent);
// interfaces
Iterator it = config.getPorts().iterator();
while(it.hasNext())
{
Port p = (Port) it.next();
if(p instanceof InterfacePort)
buildInterface((InterfacePort) p, configItem);
// TODO: FunctionPort
}
// componenets
it = config.getImplementation().getComponentAliases().iterator();
while(it.hasNext())
{
ComponentAlias c = (ComponentAlias) it.next();
if(c.getComponent() instanceof Module)
{
Module m = (Module) c.getComponent();
ModuleItem moduleItem = new ModuleItem(m, configItem);
// interfaces
Iterator it2 = m.getPorts().iterator();
while(it2.hasNext())
{
Port p = (Port) it2.next();
if(p instanceof InterfacePort)
buildInterface((InterfacePort) p, moduleItem);
// TODO: FunctionPort
}
// implementation
if( m.getImplementation()!=null && m.getImplementation().getDeclarations()!=null )
{
it2 = m.getImplementation().getDeclarations().iterator();
while(it2.hasNext())
{
Declaration d = (Declaration) it2.next();
DeclarationItem declItem = new DeclarationItem(d, moduleItem);
}
}
}
else if(c.getComponent() instanceof Configuration)
{
if( level < MAX_TREE_LEVEL )
buildConfig((Configuration) c.getComponent(), configItem, level+1 );
}
}
}
private RootItem buildTree()
{
RootItem root = new RootItem();
List projects = TinydtProject.getTinydtProjects();
Iterator it = projects.iterator();
while(it.hasNext())
{
TinydtProject proj = (TinydtProject) it.next();
ProjectItem projItem = new ProjectItem(proj, root);
Configuration config = proj.getCurrentConfiguration();
if(config != null)
buildConfig(config, projItem, 1);
}
return root;
}
private void updateTreeItem(BaseItem oldItem, BaseItem newItem )
{
int i;
ArrayList newChildren = new ArrayList();
// for all children in newItem
Iterator it = newItem.iterator();
while( it.hasNext() )
{
BaseItem item = (BaseItem)it.next();
// find it in old
boolean found = false;
Iterator it2 = oldItem.iterator();
while( it2.hasNext() )
{
BaseItem old = (BaseItem)it2.next();
if(old.getClass().equals(item.getClass()) && old.getLabel().equals(item.getLabel()))
{
found = true;
if( old instanceof DeclarationItem )
((DeclarationItem)old).decl = ((DeclarationItem)item).decl;
newChildren.add(old);
updateTreeItem(old,item);
break;
}
}
if( !found )
{
item.parent = oldItem;
newChildren.add(item);
}
}
oldItem.clear();
oldItem.addAll(newChildren);
}
private void updateTree()
{
System.out.println("viewer.refresh();");
RootItem newTree = buildTree();
updateTreeItem( tree, newTree );
viewer.refresh();
}
public void primitiveUpdate()
{
if( viewer!=null && viewer.getControl()!=null && viewer.getControl().getDisplay()!=null )
{
viewer.getControl().getDisplay().asyncExec(new Runnable()
{
public void run()
{
updateTree();
}
});
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?