createProfile();
}
}
private void createProfile() {
Settings settings = GlobalSettings.getInstance().newSettings();
refreshProfilesModel();
profiles.setSelectedItem(settings);
}
});
copyProfile.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (isModified(displayedSettings)) {
ListPopup confirmation = createConfirmation(
"Profile was modified, save changes to current profile?", "Yes", "No", new Runnable() {
@Override
public void run() {
exportDisplayedSettings();
copyProfile();
}
}, new Runnable() {
@Override
public void run() {
importFrom(displayedSettings);
copyProfile();
}
}, 0
);
confirmation.showInFocusCenter();
} else {
copyProfile();
}
}
private void copyProfile() {
Settings settings = GlobalSettings.getInstance().copySettings(displayedSettings);
refreshProfilesModel();
profiles.setSelectedItem(settings);
}
});
setJavaFormatterProfileModel();
setJavaScriptFormatterProfileModel();
profilesModel = createProfilesModel();
profiles.setModel(profilesModel);
profiles.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// && isSameId()
if (displayedSettings != null && getSelectedItem() != null && isModified(displayedSettings)) {
showConfirmationDialogOnProfileChange();
} else if (displayedSettings != null && getSelectedItem() != null) {
importFromInternal(getSelectedItem());
}
}
});
profiles.setRenderer(new ListCellRendererWrapper(profiles.getRenderer()) {
@Override
public void customize(JList jList, Object value, int i, boolean b, boolean b1) {
if (value != null) {
setText(((Settings) value).getName());
}
}
});
rename.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final JTextField content = new JTextField();
content.setText(displayedSettings.getName());
JBPopup balloon = PopupFactoryImpl.getInstance().createComponentPopupBuilder(content, content).createPopup();
balloon.setMinimumSize(new Dimension(200, 20));
balloon.addListener(new JBPopupListener() {
@Override
public void beforeShown(LightweightWindowEvent event) {
}
@Override
public void onClosed(LightweightWindowEvent event) {
displayedSettings.setName(content.getText());
}
});
balloon.showUnderneathOf(rename);
}
});
delete.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int selectedIndex = profiles.getSelectedIndex();
GlobalSettings.getInstance().delete(getSelectedItem(), getProject());
profiles.setModel(profilesModel = createProfilesModel());
int itemCount = profiles.getItemCount();
if (selectedIndex < itemCount && selectedIndex >= 0) {
Object itemAt = profiles.getItemAt(selectedIndex);
importFromInternal((Settings) itemAt);
profiles.setSelectedIndex(selectedIndex);
}
if (selectedIndex == itemCount && selectedIndex - 1 >= 0) {
Object itemAt = profiles.getItemAt(selectedIndex - 1);
importFromInternal((Settings) itemAt);
profiles.setSelectedIndex(selectedIndex - 1);
} else {
Settings defaultSettings = GlobalSettings.getInstance().getDefaultSettings();
importFromInternal(defaultSettings);
profiles.setSelectedItem(defaultSettings);
}
}