copyright configurable - import icon changed

This commit is contained in:
Evgeny
2012-09-14 07:25:17 +04:00
parent 94ff41c0ab
commit 623e04a914
2 changed files with 174 additions and 174 deletions
@@ -52,10 +52,10 @@ import java.awt.event.KeyEvent;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
public class CopyrightProfilesPanel extends MasterDetailsComponent implements SearchableConfigurable{
public class CopyrightProfilesPanel extends MasterDetailsComponent implements SearchableConfigurable {
private final Project myProject;
private final CopyrightManager myManager;
private final CopyrightManager myManager;
private final AtomicBoolean myInitialized = new AtomicBoolean(false);
public CopyrightProfilesPanel(Project project) {
@@ -75,62 +75,63 @@ public class CopyrightProfilesPanel extends MasterDetailsComponent implements Se
}
protected void processRemovedItems() {
Map<String, CopyrightProfile> profiles = getAllProfiles();
final List<CopyrightProfile> deleted = new ArrayList<CopyrightProfile>();
for (CopyrightProfile profile : myManager.getCopyrights()) {
if (!profiles.containsValue(profile)) {
deleted.add(profile);
}
}
for (CopyrightProfile profile : deleted) {
myManager.removeCopyright(profile);
}
Map<String, CopyrightProfile> profiles = getAllProfiles();
final List<CopyrightProfile> deleted = new ArrayList<CopyrightProfile>();
for (CopyrightProfile profile : myManager.getCopyrights()) {
if (!profiles.containsValue(profile)) {
deleted.add(profile);
}
}
for (CopyrightProfile profile : deleted) {
myManager.removeCopyright(profile);
}
}
protected boolean wasObjectStored(Object o) {
return myManager.getCopyrights().contains((CopyrightProfile) o);
}
protected boolean wasObjectStored(Object o) {
return myManager.getCopyrights().contains((CopyrightProfile)o);
}
@Nls
public String getDisplayName() {
return "Copyright Profiles";
}
@Nls
public String getDisplayName() {
return "Copyright Profiles";
}
@Nullable
@NonNls
public String getHelpTopic() {
return "copyright.profiles";
}
@NonNls
public String getHelpTopic() {
return "copyright.profiles";
}
public void apply() throws ConfigurationException {
final Set<String> profiles = new HashSet<String>();
for (int i = 0; i < myRoot.getChildCount(); i++) {
MyNode node = (MyNode) myRoot.getChildAt(i);
final String profileName = ((CopyrightConfigurable) node.getConfigurable()).getEditableObject().getName();
if (profiles.contains(profileName)) {
selectNodeInTree(profileName);
throw new ConfigurationException("Duplicate copyright profile name: \'" + profileName + "\'");
}
profiles.add(profileName);
}
super.apply();
public void apply() throws ConfigurationException {
final Set<String> profiles = new HashSet<String>();
for (int i = 0; i < myRoot.getChildCount(); i++) {
MyNode node = (MyNode)myRoot.getChildAt(i);
final String profileName = ((CopyrightConfigurable)node.getConfigurable()).getEditableObject().getName();
if (profiles.contains(profileName)) {
selectNodeInTree(profileName);
throw new ConfigurationException("Duplicate copyright profile name: \'" + profileName + "\'");
}
profiles.add(profileName);
}
super.apply();
}
public Map<String, CopyrightProfile> getAllProfiles() {
final Map<String, CopyrightProfile> profiles = new HashMap<String, CopyrightProfile>();
if (!myInitialized.get()) {
for (CopyrightProfile profile : myManager.getCopyrights()) {
profiles.put(profile.getName(), profile);
}
} else {
for (int i = 0; i < myRoot.getChildCount(); i++) {
MyNode node = (MyNode) myRoot.getChildAt(i);
final CopyrightProfile copyrightProfile = ((CopyrightConfigurable) node.getConfigurable()).getEditableObject();
profiles.put(copyrightProfile.getName(), copyrightProfile);
}
}
return profiles;
public Map<String, CopyrightProfile> getAllProfiles() {
final Map<String, CopyrightProfile> profiles = new HashMap<String, CopyrightProfile>();
if (!myInitialized.get()) {
for (CopyrightProfile profile : myManager.getCopyrights()) {
profiles.put(profile.getName(), profile);
}
}
else {
for (int i = 0; i < myRoot.getChildCount(); i++) {
MyNode node = (MyNode)myRoot.getChildAt(i);
final CopyrightProfile copyrightProfile = ((CopyrightConfigurable)node.getConfigurable()).getEditableObject();
profiles.put(copyrightProfile.getName(), copyrightProfile);
}
}
return profiles;
}
@Override
public void disposeUIResources() {
@@ -139,139 +140,140 @@ public class CopyrightProfilesPanel extends MasterDetailsComponent implements Se
}
@Nullable
protected ArrayList<AnAction> createActions(boolean fromPopup) {
ArrayList<AnAction> result = new ArrayList<AnAction>();
result.add(new AnAction("Add", "Add", IconUtil.getAddIcon()) {
{
registerCustomShortcutSet(CommonShortcuts.INSERT, myTree);
}
public void actionPerformed(AnActionEvent event) {
final String name = askForProfileName("Create Copyright Profile", "");
if (name == null) return;
final CopyrightProfile copyrightProfile = new CopyrightProfile(name);
addProfileNode(copyrightProfile);
}
protected ArrayList<AnAction> createActions(boolean fromPopup) {
ArrayList<AnAction> result = new ArrayList<AnAction>();
result.add(new AnAction("Add", "Add", IconUtil.getAddIcon()) {
{
registerCustomShortcutSet(CommonShortcuts.INSERT, myTree);
}
public void actionPerformed(AnActionEvent event) {
final String name = askForProfileName("Create Copyright Profile", "");
if (name == null) return;
final CopyrightProfile copyrightProfile = new CopyrightProfile(name);
addProfileNode(copyrightProfile);
}
});
result.add(new MyDeleteAction(forAll(Conditions.alwaysTrue())));
result.add(new AnAction("Copy", "Copy", PlatformIcons.COPY_ICON) {
{
registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_D, KeyEvent.CTRL_MASK)), myTree);
}
});
result.add(new MyDeleteAction(forAll(Conditions.alwaysTrue())));
result.add(new AnAction("Copy", "Copy", PlatformIcons.COPY_ICON) {
{
registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_D, KeyEvent.CTRL_MASK)), myTree);
}
public void actionPerformed(AnActionEvent event) {
final String profileName = askForProfileName("Copy Copyright Profile", "");
if (profileName == null) return;
final CopyrightProfile clone = new CopyrightProfile();
clone.copyFrom((CopyrightProfile) getSelectedObject());
clone.setName(profileName);
addProfileNode(clone);
}
public void actionPerformed(AnActionEvent event) {
final String profileName = askForProfileName("Copy Copyright Profile", "");
if (profileName == null) return;
final CopyrightProfile clone = new CopyrightProfile();
clone.copyFrom((CopyrightProfile)getSelectedObject());
clone.setName(profileName);
addProfileNode(clone);
}
public void update(AnActionEvent event) {
super.update(event);
event.getPresentation().setEnabled(getSelectedObject() != null);
}
});
result.add(new AnAction("Import", "Import", PlatformIcons.ADVICE_ICON) {
public void actionPerformed(AnActionEvent event) {
final OpenProjectFileChooserDescriptor descriptor = new OpenProjectFileChooserDescriptor(true) {
@Override
public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
return super.isFileVisible(file, showHiddenFiles) || canContainCopyright(file);
}
@Override
public boolean isFileSelectable(VirtualFile file) {
return super.isFileSelectable(file) || canContainCopyright(file);
}
private boolean canContainCopyright(VirtualFile file) {
return !file.isDirectory() && (file.getFileType() == StdFileTypes.IDEA_MODULE || file.getFileType() == StdFileTypes.XML);
}
};
descriptor.setTitle("Choose file containing copyright notice");
final VirtualFile file = FileChooser.chooseFile(descriptor, myProject, null);
if (file == null) return;
final List<CopyrightProfile> copyrightProfiles = ExternalOptionHelper.loadOptions(VfsUtil.virtualToIoFile(file));
if (copyrightProfiles == null) return;
if (!copyrightProfiles.isEmpty()) {
if (copyrightProfiles.size() == 1) {
importProfile(copyrightProfiles.get(0));
} else {
JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<CopyrightProfile>("Choose profile to import", copyrightProfiles) {
@Override
public PopupStep onChosen(final CopyrightProfile selectedValue, boolean finalChoice) {
return doFinalStep(new Runnable(){
public void run() {
importProfile(selectedValue);
}
});
}
@NotNull
@Override
public String getTextFor(CopyrightProfile value) {
return value.getName();
}
}).showUnderneathOf(myNorthPanel);
}
}
else {
Messages.showWarningDialog(myProject, "The selected file does not contain any copyright settings.", "Import Failure");
}
public void update(AnActionEvent event) {
super.update(event);
event.getPresentation().setEnabled(getSelectedObject() != null);
}
});
result.add(new AnAction("Import", "Import", PlatformIcons.IMPORT_ICON) {
public void actionPerformed(AnActionEvent event) {
final OpenProjectFileChooserDescriptor descriptor = new OpenProjectFileChooserDescriptor(true) {
@Override
public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
return super.isFileVisible(file, showHiddenFiles) || canContainCopyright(file);
}
private void importProfile(CopyrightProfile copyrightProfile) {
final String profileName = askForProfileName("Import copyright profile", copyrightProfile.getName());
if (profileName == null) return;
copyrightProfile.setName(profileName);
addProfileNode(copyrightProfile);
Messages.showInfoMessage(myProject, "The copyright settings have been successfully imported.", "Import Complete");
@Override
public boolean isFileSelectable(VirtualFile file) {
return super.isFileSelectable(file) || canContainCopyright(file);
}
});
return result;
}
private boolean canContainCopyright(VirtualFile file) {
return !file.isDirectory() && (file.getFileType() == StdFileTypes.IDEA_MODULE || file.getFileType() == StdFileTypes.XML);
}
};
descriptor.setTitle("Choose file containing copyright notice");
final VirtualFile file = FileChooser.chooseFile(descriptor, myProject, null);
if (file == null) return;
final List<CopyrightProfile> copyrightProfiles = ExternalOptionHelper.loadOptions(VfsUtil.virtualToIoFile(file));
if (copyrightProfiles == null) return;
if (!copyrightProfiles.isEmpty()) {
if (copyrightProfiles.size() == 1) {
importProfile(copyrightProfiles.get(0));
}
else {
JBPopupFactory.getInstance()
.createListPopup(new BaseListPopupStep<CopyrightProfile>("Choose profile to import", copyrightProfiles) {
@Override
public PopupStep onChosen(final CopyrightProfile selectedValue, boolean finalChoice) {
return doFinalStep(new Runnable() {
public void run() {
importProfile(selectedValue);
}
});
}
@NotNull
@Override
public String getTextFor(CopyrightProfile value) {
return value.getName();
}
}).showUnderneathOf(myNorthPanel);
}
}
else {
Messages.showWarningDialog(myProject, "The selected file does not contain any copyright settings.", "Import Failure");
}
}
private void importProfile(CopyrightProfile copyrightProfile) {
final String profileName = askForProfileName("Import copyright profile", copyrightProfile.getName());
if (profileName == null) return;
copyrightProfile.setName(profileName);
addProfileNode(copyrightProfile);
Messages.showInfoMessage(myProject, "The copyright settings have been successfully imported.", "Import Complete");
}
});
return result;
}
@Nullable
private String askForProfileName(String title, String initialName) {
return Messages.showInputDialog("New copyright profile name:", title, Messages.getQuestionIcon(), initialName, new InputValidator() {
public boolean checkInput(String s) {
return !getAllProfiles().containsKey(s) && s.length() > 0;
}
public boolean canClose(String s) {
return checkInput(s);
}
});
}
private void addProfileNode(CopyrightProfile copyrightProfile) {
final CopyrightConfigurable copyrightConfigurable = new CopyrightConfigurable(myProject, copyrightProfile, TREE_UPDATER);
copyrightConfigurable.setModified(true);
final MyNode node = new MyNode(copyrightConfigurable);
addNode(node, myRoot);
selectNodeInTree(node);
}
private void reloadTree() {
myRoot.removeAllChildren();
Collection<CopyrightProfile> collection = myManager.getCopyrights();
for (CopyrightProfile profile : collection) {
CopyrightProfile clone = new CopyrightProfile();
clone.copyFrom(profile);
addNode(new MyNode(new CopyrightConfigurable(myProject, clone, TREE_UPDATER)), myRoot);
return Messages.showInputDialog("New copyright profile name:", title, Messages.getQuestionIcon(), initialName, new InputValidator() {
public boolean checkInput(String s) {
return !getAllProfiles().containsKey(s) && s.length() > 0;
}
myInitialized.set(true);
}
public void reset() {
reloadTree();
super.reset();
public boolean canClose(String s) {
return checkInput(s);
}
});
}
private void addProfileNode(CopyrightProfile copyrightProfile) {
final CopyrightConfigurable copyrightConfigurable = new CopyrightConfigurable(myProject, copyrightProfile, TREE_UPDATER);
copyrightConfigurable.setModified(true);
final MyNode node = new MyNode(copyrightConfigurable);
addNode(node, myRoot);
selectNodeInTree(node);
}
private void reloadTree() {
myRoot.removeAllChildren();
Collection<CopyrightProfile> collection = myManager.getCopyrights();
for (CopyrightProfile profile : collection) {
CopyrightProfile clone = new CopyrightProfile();
clone.copyFrom(profile);
addNode(new MyNode(new CopyrightConfigurable(myProject, clone, TREE_UPDATER)), myRoot);
}
myInitialized.set(true);
}
public void reset() {
reloadTree();
super.reset();
}
@Override
protected String getEmptySelectionString() {
@@ -147,7 +147,7 @@
</constraints>
<properties>
<labelFor value="fcbea"/>
<text value="Length"/>
<text value="Length:"/>
</properties>
</component>
<component id="7a6fe" class="javax.swing.JLabel" binding="lblLengthAfter">
@@ -156,7 +156,7 @@
</constraints>
<properties>
<labelFor value="ee688"/>
<text value="Length"/>
<text value="Length:"/>
</properties>
</component>
<component id="fcbea" class="javax.swing.JTextField" binding="txtLengthBefore">
@@ -189,7 +189,7 @@
</constraints>
<properties>
<labelFor value="679a0"/>
<text value="Separator"/>
<text value="Separator:"/>
</properties>
</component>
<component id="30865" class="javax.swing.JCheckBox" binding="cbBox">
@@ -203,9 +203,7 @@
<component id="679a0" class="javax.swing.JTextField" binding="txtFiller">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="20" height="-1"/>
<preferred-size width="20" height="-1"/>
<maximum-size width="20" height="-1"/>
<preferred-size width="50" height="-1"/>
</grid>
</constraints>
<properties/>