2 * Copyright 2006 Sascha Weinreuter
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.intellij
.plugins
.intelliLang
.inject
.config
.ui
;
18 import com
.intellij
.javaee
.ExternalResourceManager
;
19 import com
.intellij
.openapi
.application
.ApplicationManager
;
20 import com
.intellij
.openapi
.module
.Module
;
21 import com
.intellij
.openapi
.module
.ModuleManager
;
22 import com
.intellij
.openapi
.project
.Project
;
23 import com
.intellij
.openapi
.ui
.ComboBox
;
24 import com
.intellij
.openapi
.util
.Computable
;
25 import com
.intellij
.openapi
.util
.Key
;
26 import com
.intellij
.ui
.EditorTextField
;
27 import org
.intellij
.lang
.regexp
.RegExpLanguage
;
28 import org
.intellij
.plugins
.intelliLang
.inject
.config
.AbstractTagInjection
;
29 import org
.intellij
.plugins
.intelliLang
.inject
.config
.JspSupportProxy
;
30 import org
.intellij
.plugins
.intelliLang
.inject
.config
.XmlTagInjection
;
31 import org
.intellij
.plugins
.intelliLang
.util
.LanguageTextField
;
34 import java
.util
.ArrayList
;
35 import java
.util
.Arrays
;
36 import java
.util
.Collections
;
37 import java
.util
.List
;
39 public class TagPanel
extends AbstractInjectionPanel
<AbstractTagInjection
> {
40 public static final Key
<List
<String
>> URI_MODEL
= Key
.create("URI_MODEL");
42 private JPanel myRoot
;
44 private EditorTextField myLocalName
;
45 private ComboBox myNamespace
;
46 private JCheckBox myApplyRecursivelyCheckBox
;
48 public TagPanel(Project project
, AbstractTagInjection injection
) {
49 super(injection
, project
);
52 myNamespace
.setModel(createNamespaceUriModel(myProject
));
53 myLocalName
.getDocument().addDocumentListener(new TreeUpdateListener());
56 public static ComboBoxModel
createNamespaceUriModel(Project project
) {
57 final List
<String
> data
= project
.getUserData(URI_MODEL
);
59 return new DefaultComboBoxModel(data
.toArray());
62 final List
<String
> urls
= new ArrayList
<String
>(Arrays
.asList(ExternalResourceManager
.getInstance().getResourceUrls(null, true)));
63 Collections
.sort(urls
);
65 final JspSupportProxy jspSupport
= JspSupportProxy
.getInstance();
66 if (jspSupport
!= null) {
67 final List
<String
> tlds
= new ArrayList
<String
>();
68 final Module
[] modules
= ModuleManager
.getInstance(project
).getModules();
69 for (final Module module
: modules
) {
70 final String
[] tldUris
= ApplicationManager
.getApplication().runReadAction(new Computable
<String
[]>() {
71 public String
[] compute() {
72 return jspSupport
.getPossibleTldUris(module
);
75 for (String uri
: tldUris
) {
76 if (!tlds
.contains(uri
)) {
81 Collections
.sort(tlds
);
83 // TLD URIs are intentionally kept above the other URIs to make it easier to find them
87 project
.putUserData(URI_MODEL
, urls
);
88 return new DefaultComboBoxModel(urls
.toArray());
91 public JPanel
getComponent() {
95 protected void resetImpl() {
96 myLocalName
.setText(myOrigInjection
.getTagName());
97 myNamespace
.getEditor().setItem(myOrigInjection
.getTagNamespace());
98 final boolean isXmlTag
= myOrigInjection
instanceof XmlTagInjection
;
99 myApplyRecursivelyCheckBox
.setVisible(isXmlTag
);
101 myApplyRecursivelyCheckBox
.setSelected(((XmlTagInjection
)myOrigInjection
).isApplyToSubTagTexts());
105 protected void apply(AbstractTagInjection i
) {
106 i
.setTagName(myLocalName
.getText());
107 i
.setTagNamespace(getNamespace());
108 if (i
instanceof XmlTagInjection
) {
109 ((XmlTagInjection
)i
).setApplyToSubTagTexts(myApplyRecursivelyCheckBox
.isSelected());
113 private String
getNamespace() {
114 final String s
= (String
)myNamespace
.getEditor().getItem();
115 return s
!= null ? s
: "";
118 private void createUIComponents() {
119 myLocalName
= new LanguageTextField(RegExpLanguage
.INSTANCE
, myProject
, myOrigInjection
.getTagName());
120 myNamespace
= new ComboBox(200);
123 private void $$$setupUI$$$
() {