Skip to content

Commit

Permalink
[eclipse] Add the preference page for the "errors/warnings" of SARL.
Browse files Browse the repository at this point in the history
see #125

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Nov 28, 2014
1 parent 42a87aa commit b99d673
Show file tree
Hide file tree
Showing 7 changed files with 325 additions and 11 deletions.
5 changes: 4 additions & 1 deletion plugins/io.sarl.eclipse/OSGI-INF/l10n/bundle.properties
Expand Up @@ -12,10 +12,13 @@ wizard.name.0 = SARL File
content-type.name = SARL File
propertyPage.runtimeEnvironment = Runtime Environment
preference.installedSREs = Installed SREs
preference.errorWarning = Errors/Warnings
launch.sarlApplication = SARL Application
launch.sarlLauncher = SARL Standard Launcher
launch.sarlLauncherDescription = The SARL application launcher supports running and debugging SARL applications on compatible platform.
keyword.sre = SRE
keyword.sarl = SARL
keyword.sarl.sre = SRE
keyword.sarl.runtime = Runtime
classpathContainerPage.name = SARL Libraries
sreInstallations = SRE Installation
sreInstallPages = SRE Installation Page
46 changes: 40 additions & 6 deletions plugins/io.sarl.eclipse/plugin.xml
Expand Up @@ -110,6 +110,18 @@
class="io.sarl.eclipse.preferences.SREsPreferencePage"
id="io.sarl.eclipse.preferences.SREsPreferencePage"
name="%preference.installedSREs">
<keywordReference id="io.sarl.eclipse.keyword_SARL"/>
<keywordReference id="io.sarl.eclipse.keyword_SRE"/>
<keywordReference id="io.sarl.eclipse.keyword_RUNTIME"/>
<keywordReference id="org.eclipse.jdt.ui.buildpath"/>
</page>
<page category="io.sarl.lang.SARL"
class="io.sarl.lang.ui.SARLExecutableExtensionFactory:org.eclipse.xtext.ui.validation.ValidatorPreferencePage"
id="io.sarl.eclipse.preferences.Validator"
name="%preference.errorWarning">
<keywordReference id="io.sarl.eclipse.keyword_SARL"/>
<keywordReference id="org.eclipse.jdt.ui.severities"/>
<keywordReference id="org.eclipse.jdt.ui.formatter"/>
</page>
</extension>
<extension
Expand All @@ -119,18 +131,40 @@
class="io.sarl.eclipse.properties.RuntimeEnvironmentPropertyPage"
id="io.sarl.eclipse.properties.SRE"
name="%propertyPage.runtimeEnvironment">
<keywordReference id="io.sarl.eclipse.keyword_SRE"/>
<enabledWhen>
<adapt type="org.eclipse.core.resources.IProject"/>
</enabledWhen>
<filter name="projectNature" value="io.sarl.eclipse.SARLProjectNature"/>
<keywordReference id="io.sarl.eclipse.keyword_SARL"/>
<keywordReference id="io.sarl.eclipse.keyword_SRE"/>
<keywordReference id="io.sarl.eclipse.keyword_RUNTIME"/>
<keywordReference id="org.eclipse.jdt.ui.buildpath"/>
<enabledWhen>
<adapt type="org.eclipse.core.resources.IProject"/>
</enabledWhen>
<filter name="projectNature" value="io.sarl.eclipse.SARLProjectNature"/>
</page>
<page
category="io.sarl.lang.SARL"
class="io.sarl.lang.ui.SARLExecutableExtensionFactory:org.eclipse.xtext.ui.validation.ValidatorPreferencePage"
id="io.sarl.eclipse.properties.Validator"
name="%preference.errorWarning">
<keywordReference id="io.sarl.eclipse.keyword_SARL"/>
<keywordReference id="org.eclipse.jdt.ui.severities"/>
<keywordReference id="org.eclipse.jdt.ui.formatter"/>
<enabledWhen>
<adapt type="org.eclipse.core.resources.IProject"/>
</enabledWhen>
<filter name="projectNature" value="io.sarl.eclipse.SARLProjectNature"/>
</page>
</extension>
<extension
point="org.eclipse.ui.keywords">
<keyword
id="io.sarl.eclipse.keyword_SARL"
label="%keyword.sarl"/>
<keyword
id="io.sarl.eclipse.keyword_SRE"
label="%keyword.sre"/>
label="%keyword.sarl.sre"/>
<keyword
id="io.sarl.eclipse.keyword_RUNTIME"
label="%keyword.sarl.runtime"/>
</extension>
<!--
<extension point="org.eclipse.ui.views">
Expand Down
27 changes: 23 additions & 4 deletions plugins/io.sarl.lang.ui/src/io/sarl/lang/ui/SARLUiModule.java
Expand Up @@ -26,13 +26,17 @@
import io.sarl.lang.ui.outline.SARLOperationOutlineFilter;
import io.sarl.lang.ui.outline.SARLOutlineNodeComparator;
import io.sarl.lang.ui.outline.SARLOutlinePage;
import io.sarl.lang.ui.preferences.SARLPreferenceStoreInitializer;
import io.sarl.lang.ui.preferences.SARLValidatorConfigurationBlock;
import io.sarl.lang.ui.validation.SARLUIValidator;

import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
import org.eclipse.xtext.ui.editor.outline.actions.IOutlineContribution;
import org.eclipse.xtext.ui.editor.outline.impl.OutlineFilterAndSorter.IComparator;
import org.eclipse.xtext.ui.editor.preferences.IPreferenceStoreInitializer;
import org.eclipse.xtext.ui.editor.syntaxcoloring.ISemanticHighlightingCalculator;
import org.eclipse.xtext.ui.validation.AbstractValidatorConfigurationBlock;
import org.eclipse.xtext.xbase.ui.contentassist.ImportingTypesProposalProvider;

import com.google.inject.Binder;
Expand All @@ -56,11 +60,26 @@ public SARLUiModule(AbstractUIPlugin plugin) {
super(plugin);
}

/** Replies the type of the configuration page for the SARL validator.
*
* @return the type of the SARL validator configuration page.
*/
@SuppressWarnings("static-method")
public Class<? extends AbstractValidatorConfigurationBlock> bindAbstractValidatorConfigurationBlock() {
return SARLValidatorConfigurationBlock.class;
}

@Override
public void configureSmartCaretPreferenceInitializer(Binder binder) {
binder.bind(IPreferenceStoreInitializer.class).annotatedWith(Names.named("smartCaretPreferenceInitializer")) //$NON-NLS-1$
.to(SARLPreferenceStoreInitializer.class);
}

@Override
public Class<? extends ISemanticHighlightingCalculator> bindISemanticHighlightingCalculator() {
assert (super.bindISemanticHighlightingCalculator().isAssignableFrom(SARLHighlightingCalculator.class))
: "The class SARLHighlightingCalculator does not extend the " //$NON-NLS-1$
+ "class provided by default by Xbase"; //$NON-NLS-1$
: "The class SARLHighlightingCalculator does not extend the " //$NON-NLS-1$
+ "class provided by default by Xbase"; //$NON-NLS-1$
//
return SARLHighlightingCalculator.class;
}
Expand All @@ -69,8 +88,8 @@ public Class<? extends ISemanticHighlightingCalculator> bindISemanticHighlightin
@org.eclipse.xtext.service.SingletonBinding(eager = true)
public Class<? extends org.eclipse.xtext.xbase.ui.validation.XbaseUIValidator> bindXbaseUIValidator() {
assert (super.bindXbaseUIValidator().isAssignableFrom(SARLUIValidator.class))
: "The class SARLUIValidator does not extend the class " //$NON-NLS-1$
+ "provided by default by Xbase"; //$NON-NLS-1$
: "The class SARLUIValidator does not extend the class " //$NON-NLS-1$
+ "provided by default by Xbase"; //$NON-NLS-1$
//
return SARLUIValidator.class;
}
Expand Down
@@ -0,0 +1,53 @@
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014 Sebastian RODRIGUEZ, Nicolas GAUD, Stéphane GALLAND.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.sarl.lang.ui.preferences;

import org.eclipse.osgi.util.NLS;

/** Localized Messages.
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
@SuppressWarnings("all")
public class Messages extends NLS {
private static final String BUNDLE_NAME = "io.sarl.lang.ui.preferences.messages"; //$NON-NLS-1$
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}

private Messages() {
}

public static String SARLValidatorConfigurationBlock_0;
public static String SARLValidatorConfigurationBlock_1;
public static String SARLValidatorConfigurationBlock_2;
public static String SARLValidatorConfigurationBlock_3;
public static String SARLValidatorConfigurationBlock_4;
public static String SARLValidatorConfigurationBlock_5;
public static String SARLValidatorConfigurationBlock_6;
public static String SARLValidatorConfigurationBlock_7;
public static String SARLValidatorConfigurationBlock_8;
public static String SARLValidatorConfigurationBlock_9;
}
@@ -0,0 +1,81 @@
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014 Sebastian RODRIGUEZ, Nicolas GAUD, Stéphane GALLAND.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.sarl.lang.ui.preferences;

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.xtext.preferences.PreferenceKey;
import org.eclipse.xtext.ui.editor.preferences.IPreferenceStoreAccess;
import org.eclipse.xtext.ui.editor.preferences.IPreferenceStoreInitializer;
import org.eclipse.xtext.ui.editor.preferences.PreferenceConstants;
import org.eclipse.xtext.validation.ConfigurableIssueCodesProvider;

import com.google.inject.Inject;
import com.google.inject.Singleton;

/** Initialize the preference store with SARL specific information.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
@Singleton
public class SARLPreferenceStoreInitializer implements IPreferenceStoreInitializer, IPropertyChangeListener {

private IPreferenceStoreAccess preferenceStoreAccess;

@Inject
private ConfigurableIssueCodesProvider issueCodes;

@Override
public void initialize(IPreferenceStoreAccess preferenceStoreAccess) {
this.preferenceStoreAccess = preferenceStoreAccess;
setupIssueCodesDefaults(preferenceStoreAccess);

IPreferenceStore preferenceStore = org.eclipse.jdt.ui.PreferenceConstants.getPreferenceStore();
preferenceStore.addPropertyChangeListener(this);
preferenceStoreAccess.getWritablePreferenceStore().setDefault(
PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION,
preferenceStore.getBoolean(org.eclipse.jdt.ui.PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION));

}

private void setupIssueCodesDefaults(IPreferenceStoreAccess preferenceStoreAccess) {
for (PreferenceKey prefKey : this.issueCodes.getConfigurableIssueCodes().values()) {
preferenceStoreAccess.getWritablePreferenceStore().setDefault(prefKey.getId(), prefKey.getDefaultValue());
}
}

@Override
public void propertyChange(PropertyChangeEvent event) {
if (this.preferenceStoreAccess == null) {
return;
}
if (org.eclipse.jdt.ui.PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION.equalsIgnoreCase(event.getProperty())) {
this.preferenceStoreAccess.getWritablePreferenceStore().setValue(PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION,
Boolean.valueOf(event.getNewValue().toString()));
}

}

}
@@ -0,0 +1,114 @@
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014 Sebastian RODRIGUEZ, Nicolas GAUD, Stéphane GALLAND.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.sarl.lang.ui.preferences;

import io.sarl.lang.validation.IssueCodes;

import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.xtext.validation.SeverityConverter;
import org.eclipse.xtext.xbase.ui.validation.XbaseValidationConfigurationBlock;

/** Preference page that permits to configure the SARL validator.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
public class SARLValidatorConfigurationBlock extends XbaseValidationConfigurationBlock {

private static final String SECTION_NAME = SARLValidatorConfigurationBlock.class.getName();

@Override
public void dispose() {
storeSectionExpansionStates(getDialogSettings());
super.dispose();
}

@Override
protected IDialogSettings getDialogSettings() {
IDialogSettings dialogSettings = super.getDialogSettings();
IDialogSettings section = dialogSettings.getSection(SECTION_NAME);
if (section == null) {
return dialogSettings.addNewSection(SECTION_NAME);
}
return section;
}

@Override
protected void addAdditionalComponentsToSettingsPage(Composite settingsPage, int nColumns, int defaultIndent) {
super.addAdditionalComponentsToSettingsPage(settingsPage, nColumns, defaultIndent);
createHorizontalLine(settingsPage, nColumns);
String[] values = new String[] {
SeverityConverter.SEVERITY_ERROR,
SeverityConverter.SEVERITY_WARNING,
SeverityConverter.SEVERITY_IGNORE,
};
String[] valueLabels = new String[] {
Messages.SARLValidatorConfigurationBlock_6,
Messages.SARLValidatorConfigurationBlock_7,
Messages.SARLValidatorConfigurationBlock_8,
};
Composite composite = new Composite(settingsPage, SWT.NONE);
GridLayout layout = new GridLayout(nColumns, false);
layout.marginHeight = 0;
composite.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, nColumns, 1));
composite.setLayout(layout);
addComboBox(composite,
Messages.SARLValidatorConfigurationBlock_9,
org.eclipse.xtext.xbase.validation.IssueCodes.COPY_JAVA_PROBLEMS,
defaultIndent, values, valueLabels);
}

private static void createHorizontalLine(Composite settingsPage, int nColumns) {
Label horizontalLine = new Label(settingsPage, SWT.SEPARATOR | SWT.HORIZONTAL);
horizontalLine.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, nColumns, 1));
horizontalLine.setFont(settingsPage.getFont());
}

@Override
protected void fillCodingStyleSection(ComboBoxBuilder builder) {
super.fillCodingStyleSection(builder);
builder.addComboBox(IssueCodes.REDUNDANT_INTERFACE_IMPLEMENTATION, Messages.SARLValidatorConfigurationBlock_0);
builder.addComboBox(IssueCodes.WRONG_PACKAGE, Messages.SARLValidatorConfigurationBlock_1);
}

@Override
protected void fillPotentialProgrammingProblemsSection(ComboBoxBuilder builder) {
super.fillPotentialProgrammingProblemsSection(builder);
builder.addComboBox(org.eclipse.xtext.xbase.validation.IssueCodes.VARIABLE_NAME_SHADOWING,
Messages.SARLValidatorConfigurationBlock_2);
builder.addComboBox(IssueCodes.DISCOURAGED_BOOLEAN_EXPRESSION, Messages.SARLValidatorConfigurationBlock_3);
}

@Override
protected void fillUnusedCodeSection(ComboBoxBuilder builder) {
super.fillUnusedCodeSection(builder);
builder.addComboBox(IssueCodes.DISCOURAGED_CAPACITY_DEFINITION, Messages.SARLValidatorConfigurationBlock_4);
builder.addComboBox(IssueCodes.UNREACHABLE_BEHAVIOR_UNIT, Messages.SARLValidatorConfigurationBlock_5);
}

}

0 comments on commit b99d673

Please sign in to comment.