option to run ant target before building artifact
[fedora-idea.git] / plugins / ant / src / com / intellij / lang / ant / config / impl / artifacts / AntArtifactPropertiesEditor.java
blobf85bc361b65727fc30748c309fb97ad528c47060
1 /*
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.lang.ant.config.impl.artifacts;
18 import com.intellij.lang.ant.config.AntBuildTarget;
19 import com.intellij.lang.ant.config.AntConfiguration;
20 import com.intellij.lang.ant.config.impl.artifacts.AntArtifactProperties;
21 import com.intellij.lang.ant.config.impl.TargetChooserDialog;
22 import com.intellij.openapi.project.Project;
23 import com.intellij.openapi.ui.FixedSizeButton;
24 import com.intellij.openapi.util.Comparing;
25 import com.intellij.openapi.vfs.VirtualFile;
26 import com.intellij.packaging.ui.ArtifactPropertiesEditor;
28 import javax.swing.*;
29 import java.awt.event.ActionEvent;
30 import java.awt.event.ActionListener;
32 /**
33 * @author nik
35 public class AntArtifactPropertiesEditor extends ArtifactPropertiesEditor {
36 private final AntArtifactProperties myProperties;
37 private final Project myProject;
38 private JPanel myMainPanel;
39 private JCheckBox myRunTargetCheckBox;
40 private FixedSizeButton mySelectTargetButton;
41 private AntBuildTarget myTarget;
42 private boolean myPostProcessing;
44 public AntArtifactPropertiesEditor(AntArtifactProperties properties, Project project, boolean postProcessing) {
45 myProperties = properties;
46 myProject = project;
47 myPostProcessing = postProcessing;
48 mySelectTargetButton.addActionListener(new ActionListener() {
49 public void actionPerformed(ActionEvent e) {
50 selectTarget();
52 });
53 myRunTargetCheckBox.addActionListener(new ActionListener() {
54 public void actionPerformed(ActionEvent e) {
55 mySelectTargetButton.setEnabled(myRunTargetCheckBox.isSelected());
56 if (myRunTargetCheckBox.isSelected() && myTarget == null) {
57 selectTarget();
60 });
63 private void selectTarget() {
64 final TargetChooserDialog dialog = new TargetChooserDialog(myProject, myTarget);
65 dialog.show();
66 if (dialog.isOK()) {
67 myTarget = dialog.getSelectedTarget();
68 updateLabel();
72 private void updateLabel() {
73 if (myTarget != null) {
74 myRunTargetCheckBox.setText("Run Ant target '" + myTarget.getName() + "'");
76 else {
77 myRunTargetCheckBox.setText("Run Ant target <none>");
81 public String getTabName() {
82 return myPostProcessing ? POST_PROCESSING_TAB : PRE_PROCESSING_TAB;
85 public void apply() {
86 myProperties.setEnabled(myRunTargetCheckBox.isSelected());
87 if (myTarget != null) {
88 final VirtualFile file = myTarget.getModel().getBuildFile().getVirtualFile();
89 if (file != null) {
90 myProperties.setFileUrl(file.getUrl());
91 myProperties.setTargetName(myTarget.getName());
92 return;
95 myProperties.setFileUrl(null);
96 myProperties.setTargetName(null);
99 public JComponent createComponent() {
100 return myMainPanel;
103 public boolean isModified() {
104 if (myProperties.isEnabled() != myRunTargetCheckBox.isSelected()) return true;
105 if (myTarget == null) {
106 return myProperties.getFileUrl() != null;
108 if (!Comparing.equal(myTarget.getName(), myProperties.getTargetName())) return true;
109 final VirtualFile file = myTarget.getModel().getBuildFile().getVirtualFile();
110 return file != null && !Comparing.equal(file.getUrl(), myProperties.getFileUrl());
113 public void reset() {
114 myRunTargetCheckBox.setSelected(myProperties.isEnabled());
115 myTarget = myProperties.findTarget(AntConfiguration.getInstance(myProject));
116 updateLabel();
119 public void disposeUIResources() {