2 * Copyright 2000-2009 JetBrains s.r.o.
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 com
.intellij
.javaee
;
18 import com
.intellij
.openapi
.fileChooser
.FileChooser
;
19 import com
.intellij
.openapi
.fileChooser
.FileChooserDescriptor
;
20 import com
.intellij
.openapi
.project
.Project
;
21 import com
.intellij
.openapi
.ui
.DialogWrapper
;
22 import com
.intellij
.openapi
.ui
.FixedSizeButton
;
23 import com
.intellij
.openapi
.ui
.TextFieldWithBrowseButton
;
24 import com
.intellij
.openapi
.vfs
.VirtualFile
;
25 import com
.intellij
.xml
.XmlBundle
;
29 import java
.awt
.event
.ActionEvent
;
30 import java
.awt
.event
.ActionListener
;
33 public class EditLocationDialog
extends DialogWrapper
{
35 private JTextField myTfUrl
;
36 private JTextField myTfPath
;
37 private FixedSizeButton myBtnBrowseLocalPath
;
38 private final Project myProject
;
39 private final boolean myShowPath
;
41 private final String myTitle
;
42 private final String myName
;
43 private final String myLocation
;
44 private boolean myTfShared
= true;
46 public EditLocationDialog(Project project
, boolean showPath
) {
49 myShowPath
= showPath
;
50 myTitle
= XmlBundle
.message("dialog.title.external.resource");
51 myName
= XmlBundle
.message("label.edit.external.resource.uri");
52 myLocation
= XmlBundle
.message("label.edit.external.resource.path");
56 public EditLocationDialog(Project project
, boolean showPath
, String title
, String name
, String location
) {
59 myShowPath
= showPath
;
62 myLocation
= location
;
66 protected JComponent
createCenterPanel() {
67 JPanel panel
= new JPanel(new GridBagLayout());
71 new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints
.WEST
, GridBagConstraints
.NONE
, new Insets(0, 5, 3, 5), 0, 0)
75 new GridBagConstraints(0, 1, 2, 1, 1, 0, GridBagConstraints
.WEST
, GridBagConstraints
.HORIZONTAL
, new Insets(0, 5, 5, 5), 0, 0)
78 myTfUrl
.setPreferredSize(new Dimension(350, myTfUrl
.getPreferredSize().height
));
82 new JLabel(myLocation
),
83 new GridBagConstraints(0, 2, 1, 1, 0, 0, GridBagConstraints
.WEST
, GridBagConstraints
.NONE
, new Insets(0, 5, 3, 5), 0, 0)
87 new GridBagConstraints(0, 3, 1, 1, 1, 0, GridBagConstraints
.WEST
, GridBagConstraints
.HORIZONTAL
, new Insets(0, 5, 10, 0), 0, 0)
91 new GridBagConstraints(1, 3, 1, 1, 0, 0, GridBagConstraints
.CENTER
, GridBagConstraints
.NONE
, new Insets(0, 0, 10, 5), 0, 0)
95 TextFieldWithBrowseButton
.MyDoClickAction
.addTo(myBtnBrowseLocalPath
, myTfPath
);
96 myBtnBrowseLocalPath
.addActionListener(
97 new ActionListener() {
98 public void actionPerformed(ActionEvent ignored
) {
99 FileChooserDescriptor descriptor
= getChooserDescriptor();
100 VirtualFile
[] files
= FileChooser
.chooseFiles(myProject
, descriptor
);
101 if (files
.length
!= 0) {
102 myTfPath
.setText(files
[0].getPath().replace('/', File
.separatorChar
));
114 public JComponent
getPreferredFocusedComponent() {
118 public NameLocationPair
getPair() {
119 String path
= myTfPath
.getText().trim();
120 String url
= myTfUrl
.getText().trim();
121 return new NameLocationPair(url
, path
, myTfShared
);
124 protected FileChooserDescriptor
getChooserDescriptor(){
125 return new FileChooserDescriptor(true, false, false, false, true, false);
128 protected void init() {
130 myTfUrl
= new JTextField();
131 myTfPath
= new JTextField();
132 myBtnBrowseLocalPath
= new FixedSizeButton(myTfPath
);
137 * Initializes editor with the passed data.
139 public void init(NameLocationPair origin
) {
140 myTfUrl
.setText(origin
.myName
);
141 myTfPath
.setText(origin
.myLocation
);
142 myTfShared
= origin
.myShared
;
145 public static class NameLocationPair
implements Comparable
{
150 public NameLocationPair(String name
, String location
, boolean shared
) {
152 myLocation
= location
;
156 public int compareTo(Object o
) {
157 return myName
.compareTo(((NameLocationPair
)o
).myName
);
160 public boolean equals(Object obj
) {
161 if (! (obj
instanceof NameLocationPair
)) return false;
162 return compareTo(obj
) == 0;
165 public int hashCode() {
166 return myName
.hashCode();
169 public String
getName() {
173 public String
getLocation(){