/*
 * $Id$
 *
 * SARL is an general-purpose agent programming language.
 * More details on http://www.sarl.io
 *
 * Copyright (C) 2014-2018 the original authors or authors.
 *
 * 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 static io.sarl.lang.ui.preferences.SARLBuilderPreferenceAccess.PREF_GENERATE_INLINE;
import static io.sarl.lang.ui.preferences.SARLBuilderPreferenceAccess.PREF_GENERATE_PURE;
import static io.sarl.lang.ui.preferences.SARLBuilderPreferenceAccess.PREF_USE_EXPRESSION_INTERPRETER;

import java.util.Set;

import com.google.common.collect.Sets;
import com.google.inject.Inject;
import org.eclipse.core.resources.IProject;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.xtext.builder.EclipseOutputConfigurationProvider;
import org.eclipse.xtext.generator.OutputConfiguration;
import org.eclipse.xtext.xbase.ui.builder.XbaseBuilderConfigurationBlock;

import io.sarl.lang.compiler.extra.ExtraLanguageOutputConfigurations;

/** Preference page that permits to configure the SARL builder.
 *
 * <p>This page extends the Xbase page.
 *
 * @author $Author: sgalland$
 * @version $FullVersion$
 * @mavengroupid $GroupId$
 * @mavenartifactid $ArtifactId$
 */
public class SARLBuilderConfigurationBlock extends XbaseBuilderConfigurationBlock {

	@Inject
	private EclipseOutputConfigurationProvider configurationProvider;

	@Override
	protected void createGeneralSectionItems(Composite composite) {
		super.createGeneralSectionItems(composite);

		final Button generateInlineButton = addCheckBox(composite, Messages.SARLBuilderConfigurationBlock_0,
				PREF_GENERATE_INLINE, BOOLEAN_VALUES, 0);

		final Button useExpressionInterpreter = addCheckBox(composite, Messages.SARLBuilderConfigurationBlock_1,
				PREF_USE_EXPRESSION_INTERPRETER, BOOLEAN_VALUES, INDENT_AMOUNT);
		useExpressionInterpreter.setEnabled(generateInlineButton.getSelection());

		addCheckBox(composite, Messages.SARLBuilderConfigurationBlock_2,
				PREF_GENERATE_PURE, BOOLEAN_VALUES, 0);

		generateInlineButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent event) {
				useExpressionInterpreter.setEnabled(generateInlineButton.getSelection());
			}
		});
	}

	/** Replies the output configurations for the given project.
	 *
	 * <p>This function filters the output configurations in order to never reply one
	 * associated to a extra language output.
	 *
	 * @param project the project.
	 * @return the output configurations associated to the given project.
	 */
	@Override
	protected Set<OutputConfiguration> getOutputConfigurations(IProject project) {
		final Set<OutputConfiguration> original = this.configurationProvider.getOutputConfigurations(getProject());
		return Sets.filter(original, it -> !ExtraLanguageOutputConfigurations.isExtraLanguageOutputConfiguration(it.getName()));
	}

}

@@ -2031,16 +2031,98 @@
 vider;%0A%0A
+%09private Button generateInlineButton;%0A%0A%09private Button useExpressionInterpreter;%0A%0A
 %09@Overri
@@ -2238,29 +2238,21 @@
 te);%0A%0A%09%09
-final Button 
+this.
 generate
@@ -2384,21 +2384,13 @@
 %0A%0A%09%09
-final Button 
+this.
 useE
@@ -2548,16 +2548,21 @@
 UNT);%0A%09%09
+this.
 useExpre
@@ -2581,32 +2581,37 @@
 eter.setEnabled(
+this.
 generateInlineBu
@@ -2747,16 +2747,21 @@
  0);%0A%0A%09%09
+this.
 generate
@@ -2819,16 +2819,57 @@
 ter() %7B%0A
+%09%09%09@SuppressWarnings(%22synthetic-access%22)%0A
 %09%09%09@Over
@@ -2931,16 +2931,51 @@
 ) %7B%0A%09%09%09%09
+SARLBuilderConfigurationBlock.this.
 useExpre
@@ -3002,16 +3002,58 @@
 Enabled(
+%0A%09%09%09%09%09%09SARLBuilderConfigurationBlock.this.
 generate
@@ -3097,16 +3097,311 @@
 %7D);%0A%09%7D%0A%0A
+%09@Override%0A%09protected void updateControls() %7B%0A%09%09super.updateControls();%0A%09%09// Force the enable state of the buttons.%0A%09%09if (this.useExpressionInterpreter != null && this.generateInlineButton != null) %7B%0A%09%09%09this.useExpressionInterpreter.setEnabled(this.generateInlineButton.getSelection());%0A%09%09%7D%0A%09%7D%0A%0A
 %09/** Rep

Disable "use expression interpreter" when "generate inline annotation is disabled.