private void select(String type, String name) { for (ResourceGroup group : myGroups) { if (type.equalsIgnoreCase(group.getName())) { for (ResourceItem item : group.getItems()) { if (name.equals(item.toString())) { myTreeBuilder.select(item); return; } } return; } } }
public void showPreview(@Nullable ResourceItem element) { CardLayout layout = (CardLayout) myPreviewPanel.getLayout(); if (element == null || element.getGroup().getType() == ResourceType.ID) { layout.show(myPreviewPanel, NONE); return; } try { VirtualFile file = element.getFile(); if (file == null) { String value = element.getPreviewString(); if (value == null) { java.util.List<ResourceElement> resources = element.getPreviewResources(); if (resources == null) { long time = System.currentTimeMillis(); resources = myManager.findValueResources( element.getGroup().getType().getName(), element.toString()); if (ApplicationManagerEx.getApplicationEx().isInternal()) { System.out.println("Time: " + (System.currentTimeMillis() - time)); // XXX } int size = resources.size(); if (size == 1) { value = getResourceElementValue(resources.get(0)); element.setPreviewString(value); } else if (size > 1) { resources = new ArrayList<ResourceElement>(resources); Collections.sort( resources, new Comparator<ResourceElement>() { @Override public int compare(ResourceElement element1, ResourceElement element2) { PsiDirectory directory1 = element1.getXmlTag().getContainingFile().getParent(); PsiDirectory directory2 = element2.getXmlTag().getContainingFile().getParent(); if (directory1 == null && directory2 == null) { return 0; } if (directory2 == null) { return 1; } if (directory1 == null) { return -1; } return directory1.getName().compareTo(directory2.getName()); } }); DefaultComboBoxModel model = new DefaultComboBoxModel(); String defaultSelection = null; for (int i = 0; i < size; i++) { ResourceElement resource = resources.get(i); PsiDirectory directory = resource.getXmlTag().getContainingFile().getParent(); String name = directory == null ? "unknown-" + i : directory.getName(); model.addElement(name); if (defaultSelection == null && "values".equalsIgnoreCase(name)) { defaultSelection = name; } } element.setPreviewResources(resources, model, defaultSelection); showComboPreview(element); return; } else { layout.show(myPreviewPanel, NONE); return; } } else { showComboPreview(element); return; } } if (value == null) { layout.show(myPreviewPanel, NONE); return; } myTextArea.setText(value); layout.show(myPreviewPanel, TEXT); } else if (ImageFileTypeManager.getInstance().isImage(file)) { Icon icon = element.getPreviewIcon(); if (icon == null) { icon = new SizedIcon(100, 100, new ImageIcon(file.getPath())); element.setPreviewIcon(icon); } myImageComponent.setIcon(icon); layout.show(myPreviewPanel, IMAGE); } else if (file.getFileType() == XmlFileType.INSTANCE) { String value = element.getPreviewString(); if (value == null) { value = new String(file.contentsToByteArray()); element.setPreviewString(value); } myTextArea.setText(value); myTextArea.setEditable(false); layout.show(myPreviewPanel, TEXT); } else { layout.show(myPreviewPanel, NONE); } } catch (IOException e) { layout.show(myPreviewPanel, NONE); } }