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
.sourceItems
;
18 import com
.intellij
.openapi
.actionSystem
.AnAction
;
19 import com
.intellij
.openapi
.actionSystem
.AnActionEvent
;
20 import com
.intellij
.openapi
.actionSystem
.Presentation
;
21 import com
.intellij
.openapi
.roots
.ui
.configuration
.artifacts
.ArtifactEditorEx
;
22 import com
.intellij
.openapi
.util
.text
.StringUtil
;
23 import com
.intellij
.packaging
.artifacts
.ArtifactType
;
24 import com
.intellij
.packaging
.ui
.PackagingSourceItem
;
26 import java
.util
.List
;
28 import java
.util
.HashSet
;
33 public class PutSourceItemIntoDefaultLocationAction
extends AnAction
{
34 private final SourceItemsTree mySourceItemsTree
;
35 private final ArtifactEditorEx myArtifactEditor
;
37 public PutSourceItemIntoDefaultLocationAction(SourceItemsTree sourceItemsTree
, ArtifactEditorEx artifactEditor
) {
38 mySourceItemsTree
= sourceItemsTree
;
39 myArtifactEditor
= artifactEditor
;
43 public void update(AnActionEvent e
) {
44 final ArtifactType type
= myArtifactEditor
.getArtifact().getArtifactType();
45 final List
<PackagingSourceItem
> items
= mySourceItemsTree
.getSelectedItems();
46 boolean enabled
= false;
47 final Presentation presentation
= e
.getPresentation();
48 if (!items
.isEmpty()) {
50 Set
<String
> paths
= new HashSet
<String
>();
51 for (PackagingSourceItem item
: items
) {
52 final String path
= type
.getDefaultPathFor(item
);
57 paths
.add(StringUtil
.trimStart(StringUtil
.trimEnd(path
, "/"), "/"));
59 if (paths
.size() == 1) {
60 presentation
.setText("Put Into /" + paths
.iterator().next());
63 presentation
.setText("Put into default locations");
66 presentation
.setVisible(enabled
);
67 presentation
.setEnabled(enabled
);
70 public void actionPerformed(AnActionEvent e
) {
71 myArtifactEditor
.getLayoutTreeComponent().putIntoDefaultLocations(mySourceItemsTree
.getSelectedItems());