From 623e04a914e7f6867757c91b2de142537bed9204 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Fri, 14 Sep 2012 07:25:17 +0400 Subject: [PATCH] copyright configurable - import icon changed --- .../copyright/ui/CopyrightProfilesPanel.java | 338 +++++++++--------- .../copyright/ui/TemplateCommentPanel.form | 10 +- 2 files changed, 174 insertions(+), 174 deletions(-) diff --git a/plugins/copyright/src/com/maddyhome/idea/copyright/ui/CopyrightProfilesPanel.java b/plugins/copyright/src/com/maddyhome/idea/copyright/ui/CopyrightProfilesPanel.java index a1adad6705ef..fd092ed14983 100644 --- a/plugins/copyright/src/com/maddyhome/idea/copyright/ui/CopyrightProfilesPanel.java +++ b/plugins/copyright/src/com/maddyhome/idea/copyright/ui/CopyrightProfilesPanel.java @@ -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 profiles = getAllProfiles(); - final List deleted = new ArrayList(); - for (CopyrightProfile profile : myManager.getCopyrights()) { - if (!profiles.containsValue(profile)) { - deleted.add(profile); - } - } - for (CopyrightProfile profile : deleted) { - myManager.removeCopyright(profile); - } + Map profiles = getAllProfiles(); + final List deleted = new ArrayList(); + 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 profiles = new HashSet(); - 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 profiles = new HashSet(); + 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 getAllProfiles() { - final Map profiles = new HashMap(); - 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 getAllProfiles() { + final Map profiles = new HashMap(); + 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 createActions(boolean fromPopup) { - ArrayList result = new ArrayList(); - 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 createActions(boolean fromPopup) { + ArrayList result = new ArrayList(); + 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 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("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 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("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 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 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() { diff --git a/plugins/copyright/src/com/maddyhome/idea/copyright/ui/TemplateCommentPanel.form b/plugins/copyright/src/com/maddyhome/idea/copyright/ui/TemplateCommentPanel.form index 575439743391..570a44046f24 100644 --- a/plugins/copyright/src/com/maddyhome/idea/copyright/ui/TemplateCommentPanel.form +++ b/plugins/copyright/src/com/maddyhome/idea/copyright/ui/TemplateCommentPanel.form @@ -147,7 +147,7 @@ - + @@ -156,7 +156,7 @@ - + @@ -189,7 +189,7 @@ - + @@ -203,9 +203,7 @@ - - - +