mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
MapExternalResourceDialog
This commit is contained in:
+1
-7
@@ -26,7 +26,6 @@ import com.intellij.psi.impl.source.resolve.reference.impl.providers.URLReferenc
|
||||
import com.intellij.psi.xml.XmlFile;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.xml.XmlBundle;
|
||||
import com.intellij.xml.util.XmlUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -40,13 +39,8 @@ abstract class BaseExtResourceAction extends BaseIntentionAction {
|
||||
|
||||
int offset = editor.getCaretModel().getOffset();
|
||||
String uri = findUri(file, offset);
|
||||
if (uri == null || !isAcceptableUri(uri)) return false;
|
||||
|
||||
|
||||
if (uri == null) return false;
|
||||
|
||||
XmlFile xmlFile = XmlUtil.findNamespaceByLocation(file, uri);
|
||||
if (xmlFile != null) return false;
|
||||
if (!isAcceptableUri(uri)) return false;
|
||||
setText(XmlBundle.message(getQuickFixKeyId()));
|
||||
return true;
|
||||
}
|
||||
|
||||
+12
-16
@@ -15,12 +15,10 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.javaee.ExternalResourceConfigurable;
|
||||
import com.intellij.javaee.MapExternalResourceDialog;
|
||||
import com.intellij.javaee.ExternalResourceManager;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.options.ShowSettingsUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -35,19 +33,17 @@ public class ManuallySetupExtResourceAction extends BaseExtResourceAction {
|
||||
}
|
||||
|
||||
protected void doInvoke(@NotNull final PsiFile file, final int offset, @NotNull final String uri, final Editor editor) throws IncorrectOperationException {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
ExternalResourceManager.getInstance().addResource(uri, "");
|
||||
}
|
||||
});
|
||||
|
||||
final Project project = file.getProject();
|
||||
final ExternalResourceConfigurable component = new ExternalResourceConfigurable(project);
|
||||
ShowSettingsUtil.getInstance().editConfigurable(project, component, new Runnable() {
|
||||
public void run() {
|
||||
component.selectResource(uri);
|
||||
}
|
||||
});
|
||||
final MapExternalResourceDialog dialog = new MapExternalResourceDialog(uri, file.getProject(), file, null);
|
||||
dialog.show();
|
||||
if (dialog.isOK()) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String location = dialog.getResourceLocation();
|
||||
ExternalResourceManager.getInstance().addResource(dialog.getUri(), location);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public boolean startInWriteAction() {
|
||||
|
||||
@@ -141,37 +141,4 @@ public class EditLocationDialog extends DialogWrapper {
|
||||
myTfPath.setText(origin.myLocation);
|
||||
myTfShared = origin.myShared;
|
||||
}
|
||||
|
||||
public static class NameLocationPair implements Comparable {
|
||||
String myName;
|
||||
String myLocation;
|
||||
boolean myShared;
|
||||
|
||||
public NameLocationPair(String name, String location, boolean shared) {
|
||||
myName = name;
|
||||
myLocation = location;
|
||||
myShared = shared;
|
||||
}
|
||||
|
||||
public int compareTo(Object o) {
|
||||
return myName.compareTo(((NameLocationPair)o).myName);
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (! (obj instanceof NameLocationPair)) return false;
|
||||
return compareTo(obj) == 0;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return myName.hashCode();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return myName;
|
||||
}
|
||||
|
||||
public String getLocation(){
|
||||
return myLocation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,20 +46,20 @@ import java.util.List;
|
||||
|
||||
public class ExternalResourceConfigurable extends BaseConfigurable implements SearchableConfigurable, OptionalConfigurable, Configurable.NoScroll {
|
||||
private JPanel myPanel;
|
||||
private List<EditLocationDialog.NameLocationPair> myPairs;
|
||||
private List<NameLocationPair> myPairs;
|
||||
private List<String> myIgnoredUrls;
|
||||
private String myDefaultHtmlDoctype;
|
||||
private AddEditRemovePanel<EditLocationDialog.NameLocationPair> myExtPanel;
|
||||
private AddEditRemovePanel<NameLocationPair> myExtPanel;
|
||||
private AddEditRemovePanel<String> myIgnorePanel;
|
||||
private HtmlLanguageLevelForm myHtmlLanguageLevelForm;
|
||||
@Nullable private final Project myProject;
|
||||
private final List<EditLocationDialog.NameLocationPair> myNewPairs;
|
||||
private final List<NameLocationPair> myNewPairs;
|
||||
|
||||
public ExternalResourceConfigurable(@Nullable Project project) {
|
||||
this(project, Collections.<EditLocationDialog.NameLocationPair>emptyList());
|
||||
this(project, Collections.<NameLocationPair>emptyList());
|
||||
}
|
||||
|
||||
public ExternalResourceConfigurable(@Nullable Project project, List<EditLocationDialog.NameLocationPair> newResources) {
|
||||
public ExternalResourceConfigurable(@Nullable Project project, List<NameLocationPair> newResources) {
|
||||
myProject = project;
|
||||
myNewPairs = newResources;
|
||||
}
|
||||
@@ -75,17 +75,17 @@ public class ExternalResourceConfigurable extends BaseConfigurable implements Se
|
||||
}
|
||||
};
|
||||
|
||||
myExtPanel = new AddEditRemovePanel<EditLocationDialog.NameLocationPair>(new ExtUrlsTableModel(), myPairs, XmlBundle.message("label.edit.external.resource.configure.external.resources")) {
|
||||
protected EditLocationDialog.NameLocationPair addItem() {
|
||||
myExtPanel = new AddEditRemovePanel<NameLocationPair>(new ExtUrlsTableModel(), myPairs, XmlBundle.message("label.edit.external.resource.configure.external.resources")) {
|
||||
protected NameLocationPair addItem() {
|
||||
return addExtLocation();
|
||||
}
|
||||
|
||||
protected boolean removeItem(EditLocationDialog.NameLocationPair o) {
|
||||
protected boolean removeItem(NameLocationPair o) {
|
||||
setModified(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected EditLocationDialog.NameLocationPair editItem(EditLocationDialog.NameLocationPair o) {
|
||||
protected NameLocationPair editItem(NameLocationPair o) {
|
||||
return editExtLocation(o);
|
||||
}
|
||||
};
|
||||
@@ -161,7 +161,7 @@ public class ExternalResourceConfigurable extends BaseConfigurable implements Se
|
||||
manager.clearAllResources(myProject);
|
||||
}
|
||||
for (Object myPair : myPairs) {
|
||||
EditLocationDialog.NameLocationPair pair = (EditLocationDialog.NameLocationPair)myPair;
|
||||
NameLocationPair pair = (NameLocationPair)myPair;
|
||||
String s = FileUtil.toSystemIndependentName(pair.myLocation);
|
||||
if (myProject == null || pair.myShared) {
|
||||
manager.addResource(pair.myName, s);
|
||||
@@ -186,19 +186,19 @@ public class ExternalResourceConfigurable extends BaseConfigurable implements Se
|
||||
|
||||
public void reset() {
|
||||
|
||||
myPairs = new ArrayList<EditLocationDialog.NameLocationPair>(myNewPairs);
|
||||
myPairs = new ArrayList<NameLocationPair>(myNewPairs);
|
||||
ExternalResourceManagerEx manager = ExternalResourceManagerEx.getInstanceEx();
|
||||
|
||||
String[] urls = manager.getAvailableUrls();
|
||||
for (String url : urls) {
|
||||
String loc = myProject == null ? manager.getResourceLocation(url, (String)null) : manager.getResourceLocation(url, myProject);
|
||||
myPairs.add(new EditLocationDialog.NameLocationPair(url, FileUtil.toSystemDependentName(loc), true));
|
||||
myPairs.add(new NameLocationPair(url, FileUtil.toSystemDependentName(loc), true));
|
||||
}
|
||||
if (myProject != null) {
|
||||
urls = manager.getAvailableUrls(myProject);
|
||||
for (String url : urls) {
|
||||
String loc = manager.getResourceLocation(url, myProject);
|
||||
myPairs.add(new EditLocationDialog.NameLocationPair(url, FileUtil.toSystemDependentName(loc), false));
|
||||
myPairs.add(new NameLocationPair(url, FileUtil.toSystemDependentName(loc), false));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ public class ExternalResourceConfigurable extends BaseConfigurable implements Se
|
||||
if (!myNewPairs.isEmpty()) {
|
||||
ListSelectionModel selectionModel = myExtPanel.getTable().getSelectionModel();
|
||||
selectionModel.clearSelection();
|
||||
for (EditLocationDialog.NameLocationPair newPair : myNewPairs) {
|
||||
for (NameLocationPair newPair : myNewPairs) {
|
||||
int index = myPairs.indexOf(newPair);
|
||||
selectionModel.addSelectionInterval(index, index);
|
||||
}
|
||||
@@ -243,25 +243,24 @@ public class ExternalResourceConfigurable extends BaseConfigurable implements Se
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private EditLocationDialog.NameLocationPair addExtLocation() {
|
||||
EditLocationDialog dialog = new EditLocationDialog(null, true);
|
||||
private NameLocationPair addExtLocation() {
|
||||
MapExternalResourceDialog dialog = new MapExternalResourceDialog(null, myProject, null, null);
|
||||
dialog.show();
|
||||
if (!dialog.isOK()) return null;
|
||||
setModified(true);
|
||||
return dialog.getPair();
|
||||
return new NameLocationPair(dialog.getUri(), dialog.getResourceLocation(), false);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private EditLocationDialog.NameLocationPair editExtLocation(Object o) {
|
||||
EditLocationDialog dialog = new EditLocationDialog(null, true);
|
||||
final EditLocationDialog.NameLocationPair pair = (EditLocationDialog.NameLocationPair)o;
|
||||
dialog.init(pair);
|
||||
private NameLocationPair editExtLocation(Object o) {
|
||||
NameLocationPair pair = (NameLocationPair)o;
|
||||
MapExternalResourceDialog dialog = new MapExternalResourceDialog(pair.getName(), myProject, null, pair.getLocation());
|
||||
dialog.show();
|
||||
if (!dialog.isOK()) {
|
||||
return null;
|
||||
}
|
||||
setModified(true);
|
||||
return dialog.getPair();
|
||||
return new NameLocationPair(dialog.getUri(), dialog.getResourceLocation(), pair.myShared);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -276,17 +275,13 @@ public class ExternalResourceConfigurable extends BaseConfigurable implements Se
|
||||
@Nullable
|
||||
private String editIgnoreLocation(Object o) {
|
||||
EditLocationDialog dialog = new EditLocationDialog(null, false);
|
||||
dialog.init(new EditLocationDialog.NameLocationPair(o.toString(), null, false));
|
||||
dialog.init(new NameLocationPair(o.toString(), null, false));
|
||||
dialog.show();
|
||||
if (!dialog.isOK()) return null;
|
||||
setModified(true);
|
||||
return dialog.getPair().myName;
|
||||
}
|
||||
|
||||
public void selectResource(final String uri) {
|
||||
myExtPanel.setSelected(new EditLocationDialog.NameLocationPair(uri, null, false));
|
||||
}
|
||||
|
||||
private static class PathRenderer extends DefaultTableCellRenderer {
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
final Component rendererComponent = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
||||
@@ -335,7 +330,7 @@ public class ExternalResourceConfigurable extends BaseConfigurable implements Se
|
||||
}
|
||||
}
|
||||
|
||||
private class ExtUrlsTableModel extends AddEditRemovePanel.TableModel<EditLocationDialog.NameLocationPair> {
|
||||
private class ExtUrlsTableModel extends AddEditRemovePanel.TableModel<NameLocationPair> {
|
||||
final String[] myNames;
|
||||
|
||||
{
|
||||
@@ -352,7 +347,7 @@ public class ExternalResourceConfigurable extends BaseConfigurable implements Se
|
||||
return myNames.length;
|
||||
}
|
||||
|
||||
public Object getField(EditLocationDialog.NameLocationPair pair, int columnIndex) {
|
||||
public Object getField(NameLocationPair pair, int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case 0:
|
||||
return pair.myName;
|
||||
@@ -373,7 +368,7 @@ public class ExternalResourceConfigurable extends BaseConfigurable implements Se
|
||||
return column == 2;
|
||||
}
|
||||
|
||||
public void setValue(Object aValue, EditLocationDialog.NameLocationPair data, int columnIndex) {
|
||||
public void setValue(Object aValue, NameLocationPair data, int columnIndex) {
|
||||
data.myShared = !((Boolean)aValue).booleanValue();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.javaee.MapExternalResourceDialog">
|
||||
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="95c44" class="com.intellij.ui.components.JBLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<labelFor value="3a92c"/>
|
||||
<text value="&URI:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="3a92c" class="javax.swing.JTextField" binding="myUri">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<grid id="2057d" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<tabbedpane id="c9457" class="com.intellij.ui.components.JBTabbedPane" binding="myTabs">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="39983" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<tabbedpane title="Schemas"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<scrollpane id="ec831" class="com.intellij.ui.components.JBScrollPane">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="a85b4" class="com.intellij.ui.treeStructure.Tree" binding="mySchemasTree">
|
||||
<constraints/>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</scrollpane>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="d3553" binding="myExplorerPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<tabbedpane title="Explorer"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</tabbedpane>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.javaee;
|
||||
|
||||
import com.intellij.openapi.editor.colors.EditorColorsManager;
|
||||
import com.intellij.openapi.editor.colors.EditorFontType;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.fileChooser.FileSystemTree;
|
||||
import com.intellij.openapi.fileChooser.ex.FileSystemTreeImpl;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.ui.ColoredTreeCellRenderer;
|
||||
import com.intellij.ui.DocumentAdapter;
|
||||
import com.intellij.ui.ScrollPaneFactory;
|
||||
import com.intellij.ui.components.JBTabbedPane;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.tree.TreeUtil;
|
||||
import com.intellij.xml.config.ConfigFileSearcher;
|
||||
import com.intellij.xml.config.ConfigFilesTreeBuilder;
|
||||
import com.intellij.xml.index.IndexedRelevantResource;
|
||||
import com.intellij.xml.index.XmlNamespaceIndex;
|
||||
import com.intellij.xml.index.XsdNamespaceBuilder;
|
||||
import com.intellij.xml.util.XmlUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.TreeSelectionEvent;
|
||||
import javax.swing.event.TreeSelectionListener;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.TreePath;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
* Date: 7/17/12
|
||||
*/
|
||||
public class MapExternalResourceDialog extends DialogWrapper {
|
||||
|
||||
private JTextField myUri;
|
||||
private JPanel myMainPanel;
|
||||
private JTree mySchemasTree;
|
||||
private JPanel myExplorerPanel;
|
||||
private JBTabbedPane myTabs;
|
||||
private final FileSystemTreeImpl myExplorer;
|
||||
private String myLocation;
|
||||
|
||||
|
||||
public MapExternalResourceDialog(String uri, @NotNull Project project, @Nullable PsiFile file, @Nullable String location) {
|
||||
super(project);
|
||||
setTitle("Map External Resource");
|
||||
myUri.setText(uri);
|
||||
|
||||
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
|
||||
mySchemasTree.setModel(new DefaultTreeModel(root));
|
||||
ConfigFileSearcher searcher = new ConfigFileSearcher(file == null ? null : ModuleUtilCore.findModuleForPsiElement(file), project) {
|
||||
@Override
|
||||
public Set<PsiFile> search(@Nullable Module module, @NotNull Project project) {
|
||||
List<IndexedRelevantResource<String, XsdNamespaceBuilder>> resources = XmlNamespaceIndex.getAllResources(module, project, null);
|
||||
|
||||
HashSet<PsiFile> files = new HashSet<PsiFile>();
|
||||
PsiManager psiManager = PsiManager.getInstance(project);
|
||||
for (IndexedRelevantResource<String, XsdNamespaceBuilder> resource : resources) {
|
||||
VirtualFile file = resource.getFile();
|
||||
PsiFile psiFile = psiManager.findFile(file);
|
||||
ContainerUtil.addIfNotNull(files, psiFile);
|
||||
}
|
||||
return files;
|
||||
}
|
||||
};
|
||||
searcher.search();
|
||||
new ConfigFilesTreeBuilder(mySchemasTree).buildTree(searcher, root);
|
||||
TreeUtil.expandAll(mySchemasTree);
|
||||
mySchemasTree.setRootVisible(false);
|
||||
mySchemasTree.setShowsRootHandles(true);
|
||||
|
||||
ColoredTreeCellRenderer renderer = new ColoredTreeCellRenderer() {
|
||||
@Override
|
||||
public void customizeCellRenderer(JTree tree,
|
||||
Object value,
|
||||
boolean selected,
|
||||
boolean expanded,
|
||||
boolean leaf,
|
||||
int row,
|
||||
boolean hasFocus) {
|
||||
ConfigFilesTreeBuilder.renderNode(value, expanded, this);
|
||||
}
|
||||
};
|
||||
renderer.setFont(EditorColorsManager.getInstance().getGlobalScheme().getFont(EditorFontType.PLAIN));
|
||||
|
||||
mySchemasTree.setCellRenderer(renderer);
|
||||
MouseAdapter mouseAdapter = new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.getClickCount() > 1 && isOKActionEnabled()) {
|
||||
doOKAction();
|
||||
}
|
||||
}
|
||||
};
|
||||
mySchemasTree.addMouseListener(mouseAdapter);
|
||||
|
||||
myUri.getDocument().addDocumentListener(new DocumentAdapter() {
|
||||
@Override
|
||||
protected void textChanged(DocumentEvent e) {
|
||||
validateInput();
|
||||
}
|
||||
});
|
||||
mySchemasTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
|
||||
@Override
|
||||
public void valueChanged(TreeSelectionEvent e) {
|
||||
validateInput();
|
||||
}
|
||||
});
|
||||
|
||||
myExplorer = new FileSystemTreeImpl(project, new FileChooserDescriptor(true, false, false, false, true, false));
|
||||
|
||||
myExplorer.addListener(new FileSystemTree.Listener() {
|
||||
@Override
|
||||
public void selectionChanged(List<VirtualFile> selection) {
|
||||
validateInput();
|
||||
}
|
||||
}, myExplorer);
|
||||
myExplorer.getTree().addMouseListener(mouseAdapter);
|
||||
|
||||
myExplorerPanel.add(ScrollPaneFactory.createScrollPane(myExplorer.getTree()), BorderLayout.CENTER);
|
||||
|
||||
PsiFile schema = null;
|
||||
if (file != null) {
|
||||
schema = XmlUtil.findNamespaceByLocation(file, uri);
|
||||
}
|
||||
else if (location != null) {
|
||||
VirtualFile virtualFile = VfsUtil.findRelativeFile(location, null);
|
||||
if (virtualFile != null) {
|
||||
schema = PsiManager.getInstance(project).findFile(virtualFile);
|
||||
}
|
||||
}
|
||||
|
||||
if (schema != null) {
|
||||
DefaultMutableTreeNode node = TreeUtil.findNodeWithObject(root, schema);
|
||||
if (node != null) {
|
||||
TreeUtil.selectNode(mySchemasTree, node);
|
||||
}
|
||||
myExplorer.select(schema.getVirtualFile(), null);
|
||||
}
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processDoNotAskOnOk(int exitCode) {
|
||||
super.processDoNotAskOnOk(exitCode);
|
||||
// store it since explorer will be disposed
|
||||
myLocation = getResourceLocation();
|
||||
}
|
||||
|
||||
private void validateInput() {
|
||||
setOKActionEnabled(!StringUtil.isEmpty(myUri.getText()) && getResourceLocation() != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JComponent createCenterPanel() {
|
||||
return myMainPanel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent getPreferredFocusedComponent() {
|
||||
return StringUtil.isEmpty(myUri.getText()) ? myUri : mySchemasTree;
|
||||
}
|
||||
|
||||
public String getUri() {
|
||||
return myUri.getText();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getResourceLocation() {
|
||||
if (myLocation != null) return myLocation;
|
||||
|
||||
if (myTabs.getSelectedIndex() == 0) {
|
||||
TreePath path = mySchemasTree.getSelectionPath();
|
||||
if (path == null) return null;
|
||||
Object object = ((DefaultMutableTreeNode)path.getLastPathComponent()).getUserObject();
|
||||
if (!(object instanceof PsiFile)) return null;
|
||||
return FileUtil.toSystemIndependentName(((PsiFile)object).getVirtualFile().getPath());
|
||||
}
|
||||
else {
|
||||
VirtualFile file = myExplorer.getSelectedFile();
|
||||
return file == null ? null : FileUtil.toSystemIndependentName(file.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.javaee;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
* Date: 7/18/12
|
||||
*/
|
||||
public class NameLocationPair implements Comparable {
|
||||
String myName;
|
||||
String myLocation;
|
||||
boolean myShared;
|
||||
|
||||
public NameLocationPair(String name, String location, boolean shared) {
|
||||
myName = name;
|
||||
myLocation = location;
|
||||
myShared = shared;
|
||||
}
|
||||
|
||||
public int compareTo(Object o) {
|
||||
return myName.compareTo(((NameLocationPair)o).myName);
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (! (obj instanceof NameLocationPair)) return false;
|
||||
return compareTo(obj) == 0;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return myName.hashCode();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return myName;
|
||||
}
|
||||
|
||||
public String getLocation(){
|
||||
return myLocation;
|
||||
}
|
||||
}
|
||||
+17
-9
@@ -1,33 +1,37 @@
|
||||
package com.intellij.util.xml.config;
|
||||
package com.intellij.xml.config;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class ConfigFileSearcher {
|
||||
|
||||
private final MultiMap<Module, PsiFile> myFiles = new MultiMap<Module, PsiFile>();
|
||||
private final MultiMap<VirtualFile, PsiFile> myJars = new MultiMap<VirtualFile, PsiFile>();
|
||||
private final List<VirtualFile> myVirtualFiles = new ArrayList<VirtualFile>();
|
||||
private final @NotNull Module myModule;
|
||||
private final MultiMap<VirtualFile, PsiFile> myVirtualFiles = new MultiMap<VirtualFile, PsiFile>();
|
||||
private final @Nullable Module myModule;
|
||||
@NotNull private final Project myProject;
|
||||
|
||||
public ConfigFileSearcher(@NotNull Module module) {
|
||||
public ConfigFileSearcher(@Nullable Module module, @NotNull Project project) {
|
||||
myModule = module;
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
public void search() {
|
||||
myFiles.clear();
|
||||
myJars.clear();
|
||||
|
||||
for (PsiFile file : search(myModule)) {
|
||||
PsiManager psiManager = PsiManager.getInstance(myProject);
|
||||
for (PsiFile file : search(myModule, myProject)) {
|
||||
VirtualFile jar = JarFileSystem.getInstance().getVirtualFileForJar(file.getVirtualFile());
|
||||
if (jar != null) {
|
||||
myJars.putValue(jar, file);
|
||||
@@ -37,11 +41,15 @@ public abstract class ConfigFileSearcher {
|
||||
if (module != null) {
|
||||
myFiles.putValue(module, file);
|
||||
}
|
||||
else {
|
||||
VirtualFile virtualFile = file.getVirtualFile();
|
||||
myVirtualFiles.putValue(virtualFile.getParent(), psiManager.findFile(virtualFile));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract Set<PsiFile> search(@NotNull Module module);
|
||||
public abstract Set<PsiFile> search(@Nullable Module module, @NotNull Project project);
|
||||
|
||||
public MultiMap<Module, PsiFile> getFilesByModules() {
|
||||
return myFiles;
|
||||
@@ -51,7 +59,7 @@ public abstract class ConfigFileSearcher {
|
||||
return myJars;
|
||||
}
|
||||
|
||||
public List<VirtualFile> getVirtualFiles() {
|
||||
public MultiMap<VirtualFile, PsiFile> getVirtualFiles() {
|
||||
return myVirtualFiles;
|
||||
}
|
||||
}
|
||||
+18
-9
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.util.xml.config;
|
||||
package com.intellij.xml.config;
|
||||
|
||||
import com.intellij.ide.presentation.VirtualFilePresentation;
|
||||
import com.intellij.openapi.module.Module;
|
||||
@@ -21,7 +21,6 @@ import com.intellij.openapi.module.ModuleType;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.ui.CheckedTreeNode;
|
||||
import com.intellij.ui.ColoredTreeCellRenderer;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
import com.intellij.ui.TreeSpeedSearch;
|
||||
@@ -44,6 +43,7 @@ public class ConfigFilesTreeBuilder {
|
||||
|
||||
public ConfigFilesTreeBuilder(JTree tree) {
|
||||
myTree = tree;
|
||||
installSearch(tree);
|
||||
}
|
||||
|
||||
public Set<PsiFile> buildTree(ConfigFileSearcher searcher, DefaultMutableTreeNode root) {
|
||||
@@ -51,10 +51,21 @@ public class ConfigFilesTreeBuilder {
|
||||
final MultiMap<Module,PsiFile> files = searcher.getFilesByModules();
|
||||
final MultiMap<VirtualFile, PsiFile> jars = searcher.getJars();
|
||||
final Set<PsiFile> psiFiles = buildModuleNodes(files, jars, root);
|
||||
final List<VirtualFile> virtualFiles = searcher.getVirtualFiles();
|
||||
final MultiMap<VirtualFile, PsiFile> virtualFiles = searcher.getVirtualFiles();
|
||||
|
||||
for (VirtualFile virtualFile : virtualFiles) {
|
||||
addFile(virtualFile);
|
||||
for (Map.Entry<VirtualFile, Collection<PsiFile>> entry : virtualFiles.entrySet()) {
|
||||
DefaultMutableTreeNode node = createFileNode(entry.getKey());
|
||||
List<PsiFile> list = new ArrayList<PsiFile>(entry.getValue());
|
||||
Collections.sort(list, new Comparator<PsiFile>() {
|
||||
@Override
|
||||
public int compare(PsiFile o1, PsiFile o2) {
|
||||
return o1.getName().compareToIgnoreCase(o2.getName());
|
||||
}
|
||||
});
|
||||
for (PsiFile file : list) {
|
||||
node.add(createFileNode(file));
|
||||
}
|
||||
root.add(node);
|
||||
}
|
||||
return psiFiles;
|
||||
}
|
||||
@@ -80,8 +91,7 @@ public class ConfigFilesTreeBuilder {
|
||||
}
|
||||
});
|
||||
for (Module module: modules) {
|
||||
CheckedTreeNode moduleNode = new CheckedTreeNode(module);
|
||||
moduleNode.setChecked(false);
|
||||
DefaultMutableTreeNode moduleNode = createFileNode(module);
|
||||
root.add(moduleNode);
|
||||
if (files.containsKey(module)) {
|
||||
List<PsiFile> moduleFiles = new ArrayList<PsiFile>(files.get(module));
|
||||
@@ -97,8 +107,7 @@ public class ConfigFilesTreeBuilder {
|
||||
final List<PsiFile> list = new ArrayList<PsiFile>(jars.get(file));
|
||||
final PsiFile jar = list.get(0).getManager().findFile(file);
|
||||
if (jar != null) {
|
||||
final CheckedTreeNode jarNode = new CheckedTreeNode(jar);
|
||||
jarNode.setChecked(false);
|
||||
final DefaultMutableTreeNode jarNode = createFileNode(jar);
|
||||
root.add(jarNode);
|
||||
Collections.sort(list, FILE_COMPARATOR);
|
||||
for (PsiFile psiFile: list) {
|
||||
@@ -58,13 +58,13 @@ public class IndexedRelevantResource<K, V extends Comparable> implements Compara
|
||||
}
|
||||
|
||||
public static <K, V extends Comparable> List<IndexedRelevantResource<K, V>> getAllResources(ID<K, V> indexId,
|
||||
@NotNull final Module module,
|
||||
@Nullable NullableFunction<List<IndexedRelevantResource<K, V>>, IndexedRelevantResource<K, V>> chooser) {
|
||||
@Nullable final Module module,
|
||||
@NotNull Project project,
|
||||
@Nullable NullableFunction<List<IndexedRelevantResource<K, V>>, IndexedRelevantResource<K, V>> chooser) {
|
||||
ArrayList<IndexedRelevantResource<K, V>> all = new ArrayList<IndexedRelevantResource<K, V>>();
|
||||
Collection<K> allKeys = FileBasedIndex.getInstance().getAllKeys(indexId, module.getProject());
|
||||
Collection<K> allKeys = FileBasedIndex.getInstance().getAllKeys(indexId, project);
|
||||
for (K key : allKeys) {
|
||||
List<IndexedRelevantResource<K, V>> resources = getResources(indexId, key, module, module.getProject(),
|
||||
null);
|
||||
List<IndexedRelevantResource<K, V>> resources = getResources(indexId, key, module, project, null);
|
||||
if (!resources.isEmpty()) {
|
||||
if (chooser == null) {
|
||||
all.add(resources.get(0));
|
||||
|
||||
@@ -54,13 +54,10 @@ public class XmlNamespaceIndex extends XmlIndex<XsdNamespaceBuilder> {
|
||||
return resources;
|
||||
}
|
||||
|
||||
public static List<IndexedRelevantResource<String, XsdNamespaceBuilder>> getAllResources(@NotNull final Module module) {
|
||||
return getAllResources(module, null);
|
||||
}
|
||||
|
||||
public static List<IndexedRelevantResource<String, XsdNamespaceBuilder>> getAllResources(@NotNull final Module module,
|
||||
public static List<IndexedRelevantResource<String, XsdNamespaceBuilder>> getAllResources(@Nullable final Module module,
|
||||
@NotNull Project project,
|
||||
@Nullable NullableFunction<List<IndexedRelevantResource<String, XsdNamespaceBuilder>>, IndexedRelevantResource<String, XsdNamespaceBuilder>> chooser) {
|
||||
return IndexedRelevantResource.getAllResources(NAME, module, chooser);
|
||||
return IndexedRelevantResource.getAllResources(NAME, module, project, chooser);
|
||||
}
|
||||
|
||||
private static final ID<String,XsdNamespaceBuilder> NAME = ID.create("XmlNamespaces");
|
||||
|
||||
@@ -246,7 +246,7 @@ public class XmlUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static XmlFile findNamespaceByLocation(PsiFile base, @NotNull String nsLocation) {
|
||||
public static XmlFile findNamespaceByLocation(@NotNull PsiFile base, @NotNull String nsLocation) {
|
||||
final String location = ExternalResourceManager.getInstance().getResourceLocation(nsLocation, base.getProject());
|
||||
return findXmlFile(base, location);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user