update copyright
[fedora-idea.git] / java / idea-ui / src / com / intellij / openapi / roots / ui / configuration / JavaContentRootPanel.java
blob2e54148008ea7d9319f9a285fccda7aa0aef2b52
1 /*
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.openapi.roots.ui.configuration;
18 import com.intellij.openapi.project.ProjectBundle;
19 import com.intellij.openapi.roots.ContentEntry;
20 import com.intellij.openapi.roots.ContentFolder;
21 import com.intellij.openapi.roots.SourceFolder;
22 import com.intellij.openapi.roots.ExcludeFolder;
23 import com.intellij.openapi.ui.Messages;
24 import com.intellij.openapi.util.IconLoader;
25 import com.intellij.openapi.vfs.VirtualFile;
26 import com.intellij.ui.roots.IconActionComponent;
27 import org.jetbrains.annotations.Nullable;
29 import javax.swing.*;
30 import java.awt.*;
31 import java.util.ArrayList;
33 public class JavaContentRootPanel extends ContentRootPanel {
34 private static final Color SOURCES_COLOR = new Color(0x0A50A1);
35 private static final Icon ADD_PREFIX_ICON = IconLoader.getIcon("/modules/setPackagePrefix.png");
36 private static final Icon ADD_PREFIX_ROLLOVER_ICON = IconLoader.getIcon("/modules/setPackagePrefixRollover.png");
38 public JavaContentRootPanel(ContentEntry contentEntry, ActionCallback callback) {
39 super(contentEntry, callback);
42 @Nullable
43 protected JComponent createAdditionalComponent(ContentFolder folder) {
44 if (folder instanceof SourceFolder) {
45 return createAddPrefixComponent((SourceFolder)folder);
47 return null;
50 private JComponent createAddPrefixComponent(final SourceFolder folder) {
51 final IconActionComponent iconComponent = new IconActionComponent(ADD_PREFIX_ICON, ADD_PREFIX_ROLLOVER_ICON,
52 ProjectBundle.message("module.paths.package.prefix.tooltip"), new Runnable() {
53 public void run() {
54 final String message = ProjectBundle.message("module.paths.package.prefix.prompt",
55 toRelativeDisplayPath(folder.getUrl(), myContentEntry.getUrl() + ":"));
56 final String prefix = Messages.showInputDialog(JavaContentRootPanel.this, message,
57 ProjectBundle.message("module.paths.package.prefix.title"), Messages.getQuestionIcon(), folder.getPackagePrefix(), null);
58 if (prefix != null) {
59 myCallback.setPackagePrefix(folder, prefix);
62 });
63 final JPanel panel = new JPanel(new BorderLayout());
64 panel.setOpaque(false);
65 panel.add(iconComponent, BorderLayout.CENTER);
66 panel.add(Box.createHorizontalStrut(3), BorderLayout.EAST);
67 return panel;
70 protected void addFolderGroupComponents() {
71 final java.util.List<ContentFolder> sources = new ArrayList<ContentFolder>();
72 final java.util.List<ContentFolder> testSources = new ArrayList<ContentFolder>();
73 final java.util.List<ContentFolder> excluded = new ArrayList<ContentFolder>();
74 final SourceFolder[] sourceFolders = myContentEntry.getSourceFolders();
75 for (SourceFolder folder : sourceFolders) {
76 if (folder.isSynthetic()) {
77 continue;
79 final VirtualFile folderFile = folder.getFile();
80 if (folderFile != null && (isExcluded(folderFile) || isUnderExcludedDirectory(folderFile))) {
81 continue;
83 if (folder.isTestSource()) {
84 testSources.add(folder);
86 else {
87 sources.add(folder);
91 final ExcludeFolder[] excludeFolders = myContentEntry.getExcludeFolders();
92 for (final ExcludeFolder excludeFolder : excludeFolders) {
93 if (!excludeFolder.isSynthetic()) {
94 excluded.add(excludeFolder);
98 if (sources.size() > 0) {
99 final JComponent sourcesComponent = createFolderGroupComponent(ProjectBundle.message("module.paths.sources.group"), sources.toArray(new ContentFolder[sources.size()]), SOURCES_COLOR);
100 this.add(sourcesComponent, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 10, 0), 0, 0));
102 if (testSources.size() > 0) {
103 final JComponent testSourcesComponent = createFolderGroupComponent(ProjectBundle.message("module.paths.test.sources.group"), testSources.toArray(new ContentFolder[testSources.size()]), TESTS_COLOR);
104 this.add(testSourcesComponent, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 10, 0), 0, 0));
106 if (excluded.size() > 0) {
107 final JComponent excludedComponent = createFolderGroupComponent(ProjectBundle.message("module.paths.excluded.group"), excluded.toArray(new ContentFolder[excluded.size()]), EXCLUDED_COLOR);
108 this.add(excludedComponent, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 10, 0), 0, 0));