Skip to content

Commit

Permalink
Removed no longer necessary wrapper from ProfileBasedPanel.
Browse files Browse the repository at this point in the history
  • Loading branch information
kelemen committed Jul 4, 2017
1 parent 6e2cee5 commit 240c5e6
Showing 1 changed file with 14 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class ProfileBasedPanel extends javax.swing.JPanel {

private final NbGradleProject project;
private final ProjectSettingsProvider.ExtensionSettings extensionSettings;
private final ProfileValuesEditorFactory2 snapshotCreator;
private final ProfileEditorFactory snapshotCreator;
private final AtomicIntProperty profileLoadCounter;
private final Map<ProfileItem, Snapshot> snapshots;

Expand All @@ -80,7 +80,7 @@ private ProfileBasedPanel(
NbGradleProject project,
ProjectSettingsProvider.ExtensionSettings extensionSettings,
final JComponent customPanel,
ProfileValuesEditorFactory2 snapshotCreator) {
ProfileEditorFactory snapshotCreator) {

ExceptionHelper.checkNotNullArgument(project, "project");
ExceptionHelper.checkNotNullArgument(extensionSettings, "extensionSettings");
Expand Down Expand Up @@ -152,53 +152,20 @@ public static ProfileBasedPanel createPanel(
extensionSettings,
settingsPage.getSettingsPanel(),
settingsPage.getAsyncPanelInitializer(),
convertFactory(settingsPage.getEditorFactory()));
settingsPage.getEditorFactory());
}

private static ProfileBasedPanel createPanel(
NbGradleProject project,
ProjectSettingsProvider.ExtensionSettings extensionSettings,
JComponent customPanel,
CancelableFunction<? extends Runnable> asyncPanelInitializer,
ProfileValuesEditorFactory2 snapshotCreator) {
ProfileEditorFactory snapshotCreator) {
ProfileBasedPanel result = new ProfileBasedPanel(project, extensionSettings, customPanel, snapshotCreator);
result.fetchProfilesAndSelect(asyncPanelInitializer);
return result;
}

private static ProfileValuesEditorFactory2 convertFactory(final ProfileEditorFactory factory) {
return new ProfileValuesEditorFactory2() {
@Override
public ProfileValuesEditor2 startEditingProfile(ProfileInfo profileInfo, ActiveSettingsQuery profileQuery) {
ProfileEditor editor = factory.startEditingProfile(profileInfo, profileQuery);
return upgradeEditor(editor);
}
};
}

private static ProfileValuesEditor2 upgradeEditor(final ProfileEditor editor) {
StoredSettings initialSettings = editor.readFromSettings();
final AtomicReference<StoredSettings> currentSettingsRef = new AtomicReference<>(initialSettings);
return new ProfileValuesEditor2() {
@Override
public void displayValues() {
StoredSettings settings = currentSettingsRef.get();
settings.displaySettings();
}

@Override
public void readFromGui() {
currentSettingsRef.set(editor.readFromGui());
}

@Override
public void applyValues() {
StoredSettings settings = currentSettingsRef.get();
settings.saveSettings();
}
};
}

public void saveProperties() {
readShownProfiles();
for (Map.Entry<ProfileItem, Snapshot> entry: snapshots.entrySet()) {
Expand Down Expand Up @@ -349,7 +316,7 @@ private void loadSelectedProfile() {
public void onLoad(final ActiveSettingsQuery settings) {
String displayName = selected.toString();
ProfileInfo profileInfo = new ProfileInfo(profileKey, displayName);
ProfileValuesEditor2 editor = snapshotCreator.startEditingProfile(profileInfo, settings);
ProfileEditor editor = snapshotCreator.startEditingProfile(profileInfo, settings);
final Snapshot snapshot = new Snapshot(editor);
snapshots.put(selected, snapshot);

Expand Down Expand Up @@ -482,40 +449,29 @@ public String toString() {
}

private static final class Snapshot {
private final ProfileValuesEditor2 editor;
private final ProfileEditor editor;
private final AtomicReference<StoredSettings> currentSettingsRef;

public Snapshot(ProfileValuesEditor2 editor) {
public Snapshot(ProfileEditor editor) {
this.editor = editor;
this.currentSettingsRef = new AtomicReference<>(editor.readFromSettings());
}

private void displayValues() {
editor.displayValues();
StoredSettings settings = currentSettingsRef.get();
settings.displaySettings();
}

private void readFromGui() {
editor.readFromGui();
currentSettingsRef.set(editor.readFromGui());
}

private void applyValues() {
editor.applyValues();
StoredSettings settings = currentSettingsRef.get();
settings.saveSettings();
}
}

// ProfileValuesEditorFactory2 and ProfileValuesEditor2 are provided because the original
// interfaces are considered obsolete.

private interface ProfileValuesEditorFactory2 {
public ProfileValuesEditor2 startEditingProfile(ProfileInfo info, ActiveSettingsQuery profileQuery);
}

private interface ProfileValuesEditor2 {
public void displayValues();

public void readFromGui();

public void applyValues();
}

/**
* This method is called from within the constructor to
* initialize the form.
Expand Down

0 comments on commit 240c5e6

Please sign in to comment.