Skip to content

Commit

Permalink
Add a button to restore processor settings to default values.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mailaender committed Oct 12, 2023
1 parent 2951c6b commit ab9448e
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ private boolean isEnableEditProfiles(IProcessMethod processMethod, boolean showP
//
return enableEditProfiles;
}

@Override
public void restoreDefaults() {

throw new UnsupportedOperationException();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,10 @@ private void setTableViewerInput() {

listUI.setInput(settings.values());
}

@Override
public void restoreDefaults() {

listUI.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ public class ExtensionMessages extends NLS {
public static String useSystemOptions;
public static String noSystemOptionsAvailable;
public static String rememberDecision;
public static String resetDefaults;
public static String useSpecificOptions;
public static String processorOffersNoOptions;
public static String editProcessorOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ systemDefault=System Default
resetSettingsForSelectedProcessors=Would you like to reset the settings for the selected processors?
useSystemOptions=Use System Options
rememberDecision=Remember my decision and don't ask again.
resetDefaults=Restore Defaults
noSystemOptionsAvailable=This processor does not offer system options or they are not applicable at the moment.
useSpecificOptions=Use Specific Options
processorOffersNoOptions=This processor offers no options.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ useSystemOptions=Verwende Systemeinstellungen.
noSystemOptionsAvailable=Dieser Prozessor bietet keine Systemoptionen oder sie sind derzeit nicht anwendbar.
useSpecificOptions=Verwende spezifizierte Einstellungen.
rememberDecision=Einstellungen speichern und nicht erneut fragen.
resetDefaults=Standardwerte wiederherstellen.
processorOffersNoOptions=Dieser Prozessor bietet keine Optionen.
editProcessorOptions=Bearbeite Prozessoroptionen
selectOptionsForProcessorName=Wählen Sie die Optionen für {0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ private Composite createOptionSection(Composite parent) {
//
Listener validationListener = createValidationListener();
SelectionListener selectionListener = createSelectionListener(validationListener);
addButtonSettings(composite, validationListener, selectionListener);
//
Composite bottomComposite = new Composite(composite, SWT.NONE);
bottomComposite.setLayout(new GridLayout(2, true));
bottomComposite.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL));
addButtonResetDefaults(bottomComposite);
addButtonSettings(bottomComposite, validationListener, selectionListener);
//
return composite;
}
Expand Down Expand Up @@ -238,4 +243,19 @@ public void widgetSelected(SelectionEvent e) {
selectionListener.widgetSelected(null);
settingsUI.getControl().addChangeListener(validationListener);
}

private void addButtonResetDefaults(Composite parent) {

Button buttonResetDefaults = new Button(parent, SWT.PUSH);
buttonResetDefaults.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, true, false));
buttonResetDefaults.setText(ExtensionMessages.resetDefaults);
buttonResetDefaults.addSelectionListener(new SelectionAdapter() {

@Override
public void widgetSelected(SelectionEvent e) {

settingsUI.getControl().restoreDefaults();
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public SettingsUIControl getControl() {
return control;
}

public void update(IProcessorPreferences<T> preferences) {

loadSettingsUIProvider(preferences);
}

private SettingsUIProvider<T> loadSettingsUIProvider(IProcessorPreferences<T> preferences) {

try {
Expand Down Expand Up @@ -198,6 +203,14 @@ public String getSettings() throws IOException {
return preferences.getSerialization().toString(values);
}

@Override
public void restoreDefaults() {

for(WidgetItem widgetItem : widgetItems) {
widgetItem.restoreDefaults();
}
}

@Override
public void addChangeListener(Listener listener) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2022 Lablicate GmbH.
* Copyright (c) 2019, 2023 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -35,5 +35,7 @@ interface SettingsUIControl {
void addChangeListener(Listener listener);

Control getControl();

void restoreDefaults();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,47 @@ public InputValue getInputValue() {
return inputValue;
}

public void restoreDefaults() {

if(control instanceof Text text) {
text.setText((String)inputValue.getDefaultValue());
} else if(control instanceof Button button) {
button.setSelection(Boolean.valueOf((String)inputValue.getDefaultValue()));
} else if(control instanceof Combo combo) {
Object enumValue = getEnumFrom(inputValue.getDefaultValue(), inputValue.getRawType());
if(enumValue instanceof ILabel labelledEnum) {
setSelection(combo, labelledEnum.label());
} else {
setSelection(combo, enumValue.toString());
}
}
}

private static Object getEnumFrom(Object defaultValue, Class<?> rawType) {

if(rawType.isEnum()) {
for(Object constant : rawType.getEnumConstants()) {
if(constant.toString().equals(defaultValue)) {
return constant;
}
}
}
return defaultValue;
}

private void setSelection(Combo combo, String selection) {

String[] items = combo.getItems();
int selectedIndex = -1;
for(int i = 0; i < items.length; i++) {
if(items[i].equals(selection)) {
selectedIndex = i;
break;
}
}
combo.select(selectedIndex);
}

public ControlDecoration getControlDecoration() {

return controlDecoration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,4 +456,10 @@ private void updateInput() {
toolbarShiftControl.get().setInput(settings.values());
timeRangesControl.get().setInput(settings.values());
}

@Override
public void restoreDefaults() {

settings.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -496,4 +496,10 @@ private void setTableViewerInput() {

targetTemplateListControl.get().setInput(settings.values());
}

@Override
public void restoreDefaults() {

settings.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -463,4 +463,10 @@ private void setControl(Composite composite) {

this.control = composite;
}

@Override
public void restoreDefaults() {

settings.clear();
}
}

0 comments on commit ab9448e

Please sign in to comment.