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
.actions
;
18 import com
.intellij
.openapi
.actionSystem
.AnActionEvent
;
19 import com
.intellij
.openapi
.project
.DumbAwareAction
;
20 import com
.intellij
.openapi
.project
.ProjectBundle
;
21 import com
.intellij
.openapi
.roots
.ui
.configuration
.artifacts
.ArtifactEditorEx
;
22 import com
.intellij
.openapi
.roots
.ui
.configuration
.artifacts
.LayoutTreeComponent
;
23 import com
.intellij
.openapi
.roots
.ui
.configuration
.artifacts
.LayoutTreeSelection
;
24 import com
.intellij
.openapi
.roots
.ui
.configuration
.artifacts
.nodes
.CompositePackagingElementNode
;
25 import com
.intellij
.openapi
.roots
.ui
.configuration
.artifacts
.nodes
.PackagingElementNode
;
26 import com
.intellij
.packaging
.artifacts
.Artifact
;
27 import com
.intellij
.packaging
.elements
.ArtifactRootElement
;
28 import com
.intellij
.packaging
.elements
.CompositePackagingElement
;
29 import com
.intellij
.packaging
.elements
.PackagingElement
;
30 import com
.intellij
.packaging
.impl
.artifacts
.ArtifactUtil
;
31 import com
.intellij
.packaging
.impl
.elements
.ArtifactPackagingElement
;
32 import com
.intellij
.packaging
.ui
.ArtifactEditorContext
;
34 import java
.util
.Collections
;
39 public class InlineArtifactAction
extends DumbAwareAction
{
40 private final ArtifactEditorEx myEditor
;
42 public InlineArtifactAction(ArtifactEditorEx editor
) {
43 super(ProjectBundle
.message("action.name.inline.artifact"));
48 public void update(AnActionEvent e
) {
49 final LayoutTreeSelection selection
= myEditor
.getLayoutTreeComponent().getSelection();
50 final PackagingElementNode
<?
> node
= selection
.getNodeIfSingle();
51 PackagingElement
<?
> element
= selection
.getElementIfSingle();
52 e
.getPresentation().setEnabled(element
instanceof ArtifactPackagingElement
&& node
!= null && node
.getParentElement(element
) != null);
55 public void actionPerformed(AnActionEvent e
) {
56 final LayoutTreeComponent treeComponent
= myEditor
.getLayoutTreeComponent();
57 final LayoutTreeSelection selection
= treeComponent
.getSelection();
58 final PackagingElement
<?
> element
= selection
.getElementIfSingle();
59 final PackagingElementNode
<?
> node
= selection
.getNodeIfSingle();
60 if (node
== null || !(element
instanceof ArtifactPackagingElement
)) return;
62 final CompositePackagingElement
<?
> parent
= node
.getParentElement(element
);
63 final CompositePackagingElementNode parentNode
= node
.getParentNode();
64 if (parent
== null || parentNode
== null) {
67 if (!treeComponent
.checkCanModifyChildren(parent
, parentNode
, Collections
.singletonList(node
))) return;
69 treeComponent
.editLayout(new Runnable() {
71 parent
.removeChild(element
);
72 final ArtifactEditorContext context
= myEditor
.getContext();
73 final Artifact artifact
= ((ArtifactPackagingElement
)element
).findArtifact(context
);
74 if (artifact
!= null) {
75 final CompositePackagingElement
<?
> rootElement
= artifact
.getRootElement();
76 if (rootElement
instanceof ArtifactRootElement
<?
>) {
77 for (PackagingElement
<?
> child
: rootElement
.getChildren()) {
78 parent
.addOrFindChild(ArtifactUtil
.copyWithChildren(child
, context
.getProject()));
82 parent
.addOrFindChild(ArtifactUtil
.copyWithChildren(rootElement
, context
.getProject()));
87 treeComponent
.rebuildTree();