This repository has been archived by the owner on Apr 3, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LANG: refactor pref component validation, part 2.
- Loading branch information
1 parent
5ab6e9c
commit e362189
Showing
24 changed files
with
353 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
plugin_ide.ui/src-lang/melnorme/lang/ide/ui/preferences/ValidatedConfigBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,25 @@ | |||
/******************************************************************************* | |||
* Copyright (c) 2015 Bruno Medeiros and other Contributors. | |||
* All rights reserved. This program and the accompanying materials | |||
* are made available under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution, and is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: | |||
* Bruno Medeiros - initial API and implementation | |||
*******************************************************************************/ | |||
package melnorme.lang.ide.ui.preferences; | |||
|
|||
|
|||
import melnorme.lang.tooling.data.MultipleFieldValidation; | |||
import melnorme.util.swt.components.AbstractComponentExt; | |||
|
|||
public abstract class ValidatedConfigBlock extends AbstractComponentExt { | |||
|
|||
public final MultipleFieldValidation validation = new MultipleFieldValidation(); | |||
|
|||
public ValidatedConfigBlock() { | |||
super(); | |||
} | |||
|
|||
} |
90 changes: 90 additions & 0 deletions
90
...n_ide.ui/src-lang/melnorme/lang/ide/ui/preferences/common/AbstractComponentPrefPage2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,90 @@ | |||
/******************************************************************************* | |||
* Copyright (c) 2015 Bruno Medeiros and other Contributors. | |||
* All rights reserved. This program and the accompanying materials | |||
* are made available under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution, and is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: | |||
* Bruno Medeiros - initial API and implementation | |||
*******************************************************************************/ | |||
package melnorme.lang.ide.ui.preferences.common; | |||
|
|||
|
|||
import static melnorme.utilbox.core.Assert.AssertNamespace.assertFail; | |||
|
|||
import org.eclipse.jface.dialogs.IMessageProvider; | |||
import org.eclipse.jface.preference.IPreferenceStore; | |||
import org.eclipse.swt.widgets.Composite; | |||
|
|||
import melnorme.lang.tooling.data.IStatusMessage; | |||
import melnorme.lang.tooling.data.IValidationSource; | |||
import melnorme.lang.tooling.data.StatusLevel; | |||
import melnorme.utilbox.collections.ArrayList2; | |||
import melnorme.utilbox.fields.IDomainField; | |||
|
|||
public abstract class AbstractComponentPrefPage2 extends AbstractLangPreferencesPage { | |||
|
|||
private final ArrayList2<IValidationSource> validators = new ArrayList2<>(); | |||
|
|||
public AbstractComponentPrefPage2() { | |||
super(null); | |||
} | |||
|
|||
public AbstractComponentPrefPage2(IPreferenceStore store) { | |||
super(store); | |||
} | |||
|
|||
@Override | |||
public final void createControl(Composite parent) { | |||
super.createControl(parent); | |||
updateStatusMessage(); | |||
} | |||
|
|||
public void addValidationSource(IValidationSource validationSource) { | |||
validators.add(validationSource); | |||
} | |||
|
|||
public void addValidationStatusField(IDomainField<IStatusMessage> statusField) { | |||
IValidationSource validationSource; | |||
|
|||
if(statusField instanceof IValidationSource) { | |||
validationSource = (IValidationSource) statusField; | |||
} else { | |||
validationSource = new IValidationSource() { | |||
@Override | |||
public IStatusMessage getValidationStatus() { | |||
return statusField.getFieldValue(); | |||
} | |||
}; | |||
} | |||
addValidationSource(validationSource); | |||
statusField.addListener(() -> updateStatusMessage()); | |||
} | |||
|
|||
protected void updateStatusMessage() { | |||
if(!isControlCreated()) { | |||
return; | |||
} | |||
|
|||
IStatusMessage status = IValidationSource.getHighestStatus(validators); | |||
if(status == null) { | |||
setMessage(null); | |||
setValid(true); | |||
} else { | |||
setMessage(status.getMessage(), statusLevelToMessageType(status.getStatusLevel())); | |||
setValid(status.getStatusLevel() != StatusLevel.ERROR); | |||
} | |||
} | |||
|
|||
public static int statusLevelToMessageType(StatusLevel statusLevel) { | |||
switch (statusLevel) { | |||
case OK: return IMessageProvider.NONE; | |||
case INFO: return IMessageProvider.INFORMATION; | |||
case WARNING: return IMessageProvider.WARNING; | |||
case ERROR: return IMessageProvider.ERROR; | |||
} | |||
throw assertFail(); | |||
} | |||
|
|||
} |
Oops, something went wrong.