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
.PackagingElementNode
;
25 import com
.intellij
.packaging
.artifacts
.Artifact
;
26 import com
.intellij
.packaging
.elements
.ArtifactRootElement
;
27 import com
.intellij
.packaging
.elements
.CompositePackagingElement
;
28 import com
.intellij
.packaging
.elements
.PackagingElement
;
29 import com
.intellij
.packaging
.impl
.artifacts
.ArtifactUtil
;
30 import com
.intellij
.packaging
.impl
.elements
.ArtifactPackagingElement
;
31 import com
.intellij
.packaging
.ui
.ArtifactEditorContext
;
36 public class InlineArtifactAction
extends DumbAwareAction
{
37 private final ArtifactEditorEx myEditor
;
39 public InlineArtifactAction(ArtifactEditorEx editor
) {
40 super(ProjectBundle
.message("action.name.inline.artifact"));
45 public void update(AnActionEvent e
) {
46 final LayoutTreeSelection selection
= myEditor
.getLayoutTreeComponent().getSelection();
47 final PackagingElementNode
<?
> node
= selection
.getNodeIfSingle();
48 PackagingElement
<?
> element
= selection
.getElementIfSingle();
49 e
.getPresentation().setEnabled(element
instanceof ArtifactPackagingElement
&& node
!= null && node
.getParentElement(element
) != null);
52 public void actionPerformed(AnActionEvent e
) {
53 final LayoutTreeComponent treeComponent
= myEditor
.getLayoutTreeComponent();
54 final LayoutTreeSelection selection
= treeComponent
.getSelection();
55 final PackagingElement
<?
> element
= selection
.getElementIfSingle();
56 final PackagingElementNode
<?
> node
= selection
.getNodeIfSingle();
57 if (node
== null || !(element
instanceof ArtifactPackagingElement
)) return;
59 final CompositePackagingElement
<?
> parent
= node
.getParentElement(element
);
63 if (!treeComponent
.checkCanRemove(selection
.getNodes())) return;
64 if (!treeComponent
.checkCanAdd(null, parent
, node
)) return;
66 treeComponent
.editLayout(new Runnable() {
68 parent
.removeChild(element
);
69 final ArtifactEditorContext context
= myEditor
.getContext();
70 final Artifact artifact
= ((ArtifactPackagingElement
)element
).findArtifact(context
);
71 if (artifact
!= null) {
72 final CompositePackagingElement
<?
> rootElement
= artifact
.getRootElement();
73 if (rootElement
instanceof ArtifactRootElement
<?
>) {
74 for (PackagingElement
<?
> child
: rootElement
.getChildren()) {
75 parent
.addOrFindChild(ArtifactUtil
.copyWithChildren(child
, context
.getProject()));
79 parent
.addOrFindChild(ArtifactUtil
.copyWithChildren(rootElement
, context
.getProject()));
84 treeComponent
.rebuildTree();