List of usage examples for com.vaadin.util FileTypeResolver addExtension
public static void addExtension(String extension, String mimeType)
From source file:org.lunifera.examples.vaaclipse.demo1.e4.views.VirtualFilesystemView.java
License:Open Source License
private void createProjectTree() { demoRoot = Demo1Activator.getInstance().getSrcStore(); tree = new Tree(); tree.setSizeFull();//from ww w . j a va 2 s. c o m tree.setImmediate(true); panel.setContent(tree); FilesystemContainer fsc = new FilesystemContainer(demoRoot, true); FileTypeResolver.addExtension("java", "java"); FileTypeResolver.addIcon("java", BundleResource.valueOf("platform:/plugin/org.lunifera.examples.vaaclipse.demo1.e4/img/java.png")); FileTypeResolver.addExtension("xml", "xml"); FileTypeResolver.addIcon("xml", BundleResource.valueOf("platform:/plugin/org.lunifera.examples.vaaclipse.demo1.e4/img/xml.png")); FileTypeResolver.addExtension("e4xmi", "e4xmi"); FileTypeResolver.addIcon("e4xmi", BundleResource.valueOf("platform:/plugin/org.lunifera.examples.vaaclipse.demo1.e4/img/xmi.png")); FileTypeResolver.addExtension("css", "css"); FileTypeResolver.addIcon("css", BundleResource.valueOf("platform:/plugin/org.lunifera.examples.vaaclipse.demo1.e4/img/css.png")); FileTypeResolver.addExtension("html", "html"); FileTypeResolver.addIcon("html", BundleResource.valueOf("platform:/plugin/org.lunifera.examples.vaaclipse.demo1.e4/img/html.png")); FileTypeResolver.addIcon("image/png", BundleResource.valueOf("platform:/plugin/org.lunifera.examples.vaaclipse.demo1.e4/img/img.png")); FileTypeResolver.addIcon("inode/directory", BundleResource.valueOf("platform:/plugin/org.lunifera.examples.vaaclipse.demo1.e4/img/folder.png")); tree.setContainerDataSource(fsc); tree.addListener(new ItemClickEvent.ItemClickListener() { long lastTime = 0; File lastFile; public void itemClick(final ItemClickEvent event) { if (event.getButton() == ItemClickEvent.BUTTON_LEFT) { long time = System.currentTimeMillis(); if (lastTime > 0 && time - lastTime < 300) { tree.select(event.getItemId()); FileItem fileItem = (FileItem) event.getItem(); try { for (Field f : FilesystemContainer.FileItem.class.getDeclaredFields()) { if (f.getName().equals("file")) { f.setAccessible(true); final File file = (File) f.get(fileItem); if (!file.equals(lastFile)) { eventBroker.send(Demo1Constants.OPEN_FILE, file); lastFile = file; } break; } } } catch (Exception e) { e.printStackTrace(); } } lastTime = time; } } }); // Set tree to show the 'name' property as caption for items tree.setItemCaptionPropertyId(FilesystemContainer.PROPERTY_NAME); tree.setItemIconPropertyId(FilesystemContainer.PROPERTY_ICON); for (Object id : tree.rootItemIds()) { tree.expandItem(id); } String projectName = "org.lunifera.examples.vaaclipse.demo1.e4"; File data = FileUtils.getFile(demoRoot, projectName, "data"); if (data != null) tree.expandItem(data); File rootPackage = FileUtils.getFile(demoRoot, projectName, "src"); if (rootPackage != null) tree.expandItemsRecursively(rootPackage); }
From source file:org.semanticsoft.vaaclipsedemo.cassandra.app.views.PackageExplorer.java
License:Open Source License
private void createProjectTree() { demoRoot = CassandraActivator.getInstance().getSrcStore(); tree = new Tree(); tree.setSizeFull();/* www .j a v a2s . c o m*/ tree.setImmediate(true); panel.setContent(tree); FilesystemContainer fsc = new FilesystemContainer(demoRoot, true); FileTypeResolver.addExtension("java", "java"); FileTypeResolver.addIcon("java", BundleResource .valueOf("platform:/plugin/org.semanticsoft.vaaclipsedemo.cassandra.app/img/java.png")); FileTypeResolver.addExtension("xml", "xml"); FileTypeResolver.addIcon("xml", BundleResource .valueOf("platform:/plugin/org.semanticsoft.vaaclipsedemo.cassandra.app/img/xml.png")); FileTypeResolver.addExtension("e4xmi", "e4xmi"); FileTypeResolver.addIcon("e4xmi", BundleResource .valueOf("platform:/plugin/org.semanticsoft.vaaclipsedemo.cassandra.app/img/xmi.png")); FileTypeResolver.addExtension("css", "css"); FileTypeResolver.addIcon("css", BundleResource .valueOf("platform:/plugin/org.semanticsoft.vaaclipsedemo.cassandra.app/img/css.png")); FileTypeResolver.addExtension("html", "html"); FileTypeResolver.addIcon("html", BundleResource .valueOf("platform:/plugin/org.semanticsoft.vaaclipsedemo.cassandra.app/img/html.png")); FileTypeResolver.addIcon("image/png", BundleResource .valueOf("platform:/plugin/org.semanticsoft.vaaclipsedemo.cassandra.app/img/img.png")); FileTypeResolver.addIcon("inode/directory", BundleResource .valueOf("platform:/plugin/org.semanticsoft.vaaclipsedemo.cassandra.app/img/folder.png")); tree.setContainerDataSource(fsc); tree.addItemClickListener(new ItemClickEvent.ItemClickListener() { public void itemClick(final ItemClickEvent event) { if (event.getButton() == MouseButton.LEFT && event.isDoubleClick()) { tree.select(event.getItemId()); FileItem fileItem = (FileItem) event.getItem(); try { for (Field f : FileItem.class.getDeclaredFields()) { if (f.getName().equals("file")) { f.setAccessible(true); final File file = (File) f.get(fileItem); eventBroker.send(CassandraConstants.OPEN_FILE, file); break; } } } catch (Exception e) { e.printStackTrace(); } } } }); // Set tree to show the 'name' property as caption for items tree.setItemCaptionPropertyId(FilesystemContainer.PROPERTY_NAME); tree.setItemIconPropertyId(FilesystemContainer.PROPERTY_ICON); for (Object id : tree.rootItemIds()) { tree.expandItem(id); } String projectName = "org.semanticsoft.vaaclipsedemo.cassandra.app"; File data = FileUtils.getFile(demoRoot, projectName, "data"); if (data != null) tree.expandItem(data); File rootPackage = FileUtils.getFile(demoRoot, projectName, "src"); if (rootPackage != null) tree.expandItemsRecursively(rootPackage); }