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
.artifacts
;
18 import com
.intellij
.openapi
.Disposable
;
19 import com
.intellij
.openapi
.roots
.ui
.configuration
.artifacts
.nodes
.CompositePackagingElementNode
;
20 import com
.intellij
.openapi
.roots
.ui
.configuration
.artifacts
.nodes
.PackagingElementNode
;
21 import com
.intellij
.openapi
.util
.Disposer
;
22 import com
.intellij
.packaging
.artifacts
.Artifact
;
23 import com
.intellij
.packaging
.elements
.PackagingElement
;
24 import com
.intellij
.packaging
.impl
.ui
.ArtifactValidationManagerBase
;
25 import com
.intellij
.packaging
.ui
.ArtifactProblemQuickFix
;
26 import com
.intellij
.util
.ui
.update
.MergingUpdateQueue
;
27 import com
.intellij
.util
.ui
.update
.Update
;
28 import org
.jetbrains
.annotations
.NotNull
;
29 import org
.jetbrains
.annotations
.Nullable
;
37 public class ArtifactValidationManagerImpl
extends ArtifactValidationManagerBase
implements Disposable
{
38 private MergingUpdateQueue myValidationQueue
;
39 private ArtifactErrorPanel myErrorPanel
;
40 private final ArtifactEditorImpl myArtifactEditor
;
41 private Map
<PackagingElementNode
<?
>, String
> myErrorsForNodes
= new HashMap
<PackagingElementNode
<?
>, String
>();
42 private Map
<PackagingElement
<?
>, String
> myErrorsForElements
= new HashMap
<PackagingElement
<?
>, String
>();
44 ArtifactValidationManagerImpl(ArtifactEditorImpl artifactEditor
) {
45 super(artifactEditor
.getContext());
46 Disposer
.register(artifactEditor
, this);
47 myArtifactEditor
= artifactEditor
;
48 myErrorPanel
= new ArtifactErrorPanel(artifactEditor
);
49 final JComponent mainComponent
= artifactEditor
.getMainComponent();
50 myValidationQueue
= new MergingUpdateQueue("ArtifactValidation", 300, false, mainComponent
, this, mainComponent
);
53 private void runValidation() {
54 myErrorPanel
.clearError();
55 myErrorsForNodes
.clear();
56 myErrorsForElements
.clear();
58 myArtifactEditor
.getLayoutTreeComponent().saveElementProperties();
59 final Artifact artifact
= myArtifactEditor
.getArtifact();
60 artifact
.getArtifactType().checkRootElement(myArtifactEditor
.getRootElement(), artifact
, this);
62 myArtifactEditor
.getLayoutTreeComponent().updateTreeNodesPresentation();
65 public void registerProblem(@NotNull String message
, @Nullable PackagingElement
<?
> place
, @Nullable ArtifactProblemQuickFix quickFix
) {
67 final LayoutTree layoutTree
= myArtifactEditor
.getLayoutTreeComponent().getLayoutTree();
68 myErrorsForElements
.put(place
, message
);
69 final List
<PackagingElementNode
<?
>> nodes
= layoutTree
.findNodes(Collections
.singletonList(place
));
70 for (PackagingElementNode
<?
> node
: nodes
) {
71 addNodeToErrorsWithParents(node
, message
);
74 myErrorPanel
.showError(message
, quickFix
);
77 private void addNodeToErrorsWithParents(PackagingElementNode
<?
> node
, String message
) {
78 if (!myErrorsForNodes
.containsKey(node
)) {
79 myErrorsForNodes
.put(node
, message
);
80 final CompositePackagingElementNode parentNode
= node
.getParentNode();
81 if (parentNode
!= null) {
82 addNodeToErrorsWithParents(parentNode
, message
);
87 public void dispose() {
90 public void queueValidation() {
91 myValidationQueue
.queue(new Update("validate") {
98 public JComponent
getMainErrorPanel() {
99 return myErrorPanel
.getMainPanel();
102 public void elementAddedToNode(PackagingElementNode
<?
> node
, PackagingElement
<?
> element
) {
103 final String message
= myErrorsForElements
.get(element
);
104 if (message
!= null) {
105 addNodeToErrorsWithParents(node
, message
);
110 public String
getProblem(PackagingElementNode
<?
> node
) {
111 return myErrorsForNodes
.get(node
);