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.
17 package com
.intellij
.ide
.util
.scopeChooser
;
19 import com
.intellij
.ide
.IdeBundle
;
20 import com
.intellij
.openapi
.options
.ex
.SingleConfigurableEditor
;
21 import com
.intellij
.openapi
.project
.Project
;
22 import com
.intellij
.openapi
.ui
.DialogWrapper
;
23 import com
.intellij
.openapi
.ui
.InputValidator
;
24 import com
.intellij
.openapi
.ui
.Messages
;
25 import com
.intellij
.packageDependencies
.DependencyValidationManager
;
26 import com
.intellij
.psi
.search
.scope
.packageSet
.NamedScope
;
27 import com
.intellij
.psi
.search
.scope
.packageSet
.PackageSet
;
33 public class EditScopesDialog
extends SingleConfigurableEditor
{
34 private NamedScope mySelectedScope
;
35 private final boolean myCheckShared
;
37 public EditScopesDialog(final Project project
, final boolean checkShared
) {
38 super(project
, ScopeChooserConfigurable
.getInstance(project
), "scopes");
39 myCheckShared
= checkShared
;
42 protected void doOKAction() {
43 final Object selectedObject
= ((ScopeChooserConfigurable
)getConfigurable()).getSelectedObject();
44 if (selectedObject
instanceof NamedScope
){
45 mySelectedScope
= (NamedScope
)selectedObject
;
48 if (myCheckShared
&& mySelectedScope
!= null) {
49 final Project project
= getProject();
50 final DependencyValidationManager manager
= DependencyValidationManager
.getInstance(project
);
51 NamedScope scope
= manager
.getScope(mySelectedScope
.getName());
53 if (Messages
.showYesNoDialog(IdeBundle
.message("scope.unable.to.save.scope.message"),
54 IdeBundle
.message("scope.unable.to.save.scope.title"), Messages
.getErrorIcon()) == DialogWrapper
56 final String newName
= Messages
.showInputDialog(project
, IdeBundle
.message("add.scope.name.label"),
57 IdeBundle
.message("scopes.save.dialog.title.shared"), Messages
.getQuestionIcon(),
58 mySelectedScope
.getName(), new InputValidator() {
59 public boolean checkInput(String inputString
) {
60 return inputString
!= null && inputString
.length() > 0 && manager
.getScope(inputString
) == null;
63 public boolean canClose(String inputString
) {
64 return checkInput(inputString
);
67 if (newName
!= null) {
68 final PackageSet packageSet
= mySelectedScope
.getValue();
69 scope
= new NamedScope(newName
, packageSet
!= null ? packageSet
.createCopy() : null);
70 mySelectedScope
= scope
;
71 manager
.addScope(mySelectedScope
);
79 public static EditScopesDialog
editConfigurable(final Project project
, final Runnable advancedInitialization
){
80 return editConfigurable(project
, advancedInitialization
, false);
83 public static EditScopesDialog
editConfigurable(final Project project
, final Runnable advancedInitialization
, final boolean checkShared
){
84 final EditScopesDialog dialog
= new EditScopesDialog(project
, checkShared
);
85 if (advancedInitialization
!= null) {
86 advancedInitialization
.run();
92 public NamedScope
getSelectedScope() {
93 return mySelectedScope
;