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
.projectImport
;
18 import com
.intellij
.ide
.IdeBundle
;
19 import com
.intellij
.ide
.util
.ElementsChooser
;
20 import com
.intellij
.ide
.util
.projectWizard
.WizardContext
;
21 import com
.intellij
.openapi
.options
.ConfigurationException
;
22 import com
.intellij
.uiDesigner
.core
.GridConstraints
;
23 import com
.intellij
.uiDesigner
.core
.GridLayoutManager
;
24 import org
.jetbrains
.annotations
.Nullable
;
25 import org
.jetbrains
.annotations
.NotNull
;
31 * @author Vladislav.Kaznacheev
33 public abstract class SelectImportedProjectsStep
<T
> extends ProjectImportWizardStep
{
34 private final JPanel panel
;
35 protected final ElementsChooser
<T
> fileChooser
;
36 private final JCheckBox openModuleSettingsCheckBox
;
38 public SelectImportedProjectsStep(WizardContext context
) {
40 fileChooser
= new ElementsChooser
<T
>(true) {
41 protected String
getItemText(@NotNull T item
) {
42 return getElementText(item
);
45 protected Icon
getItemIcon(final T item
) {
46 return getElementIcon (item
);
50 panel
= new JPanel(new GridLayoutManager(2, 1, new Insets(0, 0, 0, 0), -1, -1));
52 panel
.add(fileChooser
, new GridConstraints(0, 0, 1, 1, GridConstraints
.ANCHOR_NORTH
, GridConstraints
.FILL_BOTH
,
53 GridConstraints
.SIZEPOLICY_CAN_SHRINK
| GridConstraints
.SIZEPOLICY_WANT_GROW
,
54 GridConstraints
.SIZEPOLICY_CAN_SHRINK
| GridConstraints
.SIZEPOLICY_WANT_GROW
, null, null,
56 openModuleSettingsCheckBox
= new JCheckBox(IdeBundle
.message("project.import.show.settings.after"));
57 panel
.add(openModuleSettingsCheckBox
, new GridConstraints(1, 0, 1, 1, GridConstraints
.ANCHOR_SOUTH
, GridConstraints
.FILL_HORIZONTAL
,
58 GridConstraints
.SIZEPOLICY_CAN_SHRINK
| GridConstraints
.SIZEPOLICY_WANT_GROW
,
59 GridConstraints
.SIZEPOLICY_FIXED
, null, null, null));
63 protected Icon
getElementIcon(final T item
) {
67 protected abstract String
getElementText(final T item
);
69 public JComponent
getComponent() {
73 public void updateStep() {
75 for (T element
: getContext().getList()) {
76 fileChooser
.addElement(element
, getContext().isMarked(element
));
78 fileChooser
.setBorder(BorderFactory
.createTitledBorder(IdeBundle
.message("project.import.select.title", getContext().getName())));
79 openModuleSettingsCheckBox
.setSelected(getBuilder().isOpenProjectSettingsAfter());
82 public boolean validate() throws ConfigurationException
{
83 getContext().setList(fileChooser
.getMarkedElements());
84 if (fileChooser
.getMarkedElements().size() == 0) {
85 throw new ConfigurationException("Nothing found to import", "Unable to proceed");
90 public void updateDataModel() {}
92 public void onStepLeaving() {
93 super.onStepLeaving();
94 getContext().setOpenProjectSettingsAfter(openModuleSettingsCheckBox
.isSelected());
97 public ProjectImportBuilder
<T
> getContext() {