diff --git a/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/MavenLocalizationConstant.java b/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/MavenLocalizationConstant.java index 42116de8ec6..4ae45f73615 100644 --- a/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/MavenLocalizationConstant.java +++ b/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/MavenLocalizationConstant.java @@ -67,4 +67,11 @@ public interface MavenLocalizationConstant extends Messages { @Key("maven.page.errorDialog.title") String mavenPageErrorDialogTitle(); + + /* Preferences page*/ + @Key("maven.preferences.title") + String mavenPreferencesTitle(); + + @Key("maven.preferences.show.artifact.id.checkbox.text") + String mavenPreferencesShowArtifactIdCheckboxText(); } diff --git a/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/inject/MavenGinModule.java b/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/inject/MavenGinModule.java index 0427e93f795..45de059d939 100644 --- a/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/inject/MavenGinModule.java +++ b/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/inject/MavenGinModule.java @@ -12,12 +12,15 @@ import com.google.gwt.inject.client.AbstractGinModule; import com.google.gwt.inject.client.multibindings.GinMultibinder; + import org.eclipse.che.ide.api.command.CommandType; import org.eclipse.che.ide.api.extension.ExtensionGinModule; +import org.eclipse.che.ide.api.preferences.PreferencePagePresenter; import org.eclipse.che.ide.api.project.type.wizard.ProjectWizardRegistrar; import org.eclipse.che.ide.api.resources.ResourceInterceptor; import org.eclipse.che.ide.project.ResolvingProjectStateHolder; import org.eclipse.che.plugin.maven.client.command.MavenCommandType; +import org.eclipse.che.plugin.maven.client.preference.MavenPreferencePresenter; import org.eclipse.che.plugin.maven.client.project.ResolvingMavenProjectStateHolder; import org.eclipse.che.plugin.maven.client.resource.MavenProjectInterceptor; import org.eclipse.che.plugin.maven.client.resource.MavenSourceFolderInterceptor; @@ -39,6 +42,8 @@ protected void configure() { GinMultibinder.newSetBinder(binder(), CommandType.class).addBinding().to(MavenCommandType.class); + GinMultibinder.newSetBinder(binder(), PreferencePagePresenter.class).addBinding().to(MavenPreferencePresenter.class); + GinMultibinder.newSetBinder(binder(), ResourceInterceptor.class).addBinding().to(MavenSourceFolderInterceptor.class); GinMultibinder.newSetBinder(binder(), ResourceInterceptor.class).addBinding().to(PomInterceptor.class); GinMultibinder.newSetBinder(binder(), ResourceInterceptor.class).addBinding().to(MavenProjectInterceptor.class); diff --git a/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/preference/MavenPreferencePresenter.java b/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/preference/MavenPreferencePresenter.java new file mode 100644 index 00000000000..e5d58dc6b23 --- /dev/null +++ b/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/preference/MavenPreferencePresenter.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.maven.client.preference; + +import com.google.gwt.user.client.ui.AcceptsOneWidget; +import com.google.inject.Inject; +import com.google.inject.Singleton; + +import org.eclipse.che.ide.CoreLocalizationConstant; +import org.eclipse.che.ide.api.app.AppContext; +import org.eclipse.che.ide.api.preferences.AbstractPreferencePagePresenter; +import org.eclipse.che.ide.api.preferences.PreferencesManager; +import org.eclipse.che.plugin.maven.client.MavenLocalizationConstant; + +/** + * Preference page presenter for Maven plugin. + * + * @author Igor Vinokur + */ +@Singleton +public class MavenPreferencePresenter extends AbstractPreferencePagePresenter implements MavenPreferenceView.ActionDelegate { + + public static final String PREF_SHOW_ARTIFACT_ID = "maven.artifact.in.project.explorer"; + + private final MavenPreferenceView view; + private final AppContext appContext; + private final PreferencesManager preferencesManager; + + private boolean showArtifactId; + private boolean dirty = false; + + @Inject + public MavenPreferencePresenter(MavenPreferenceView view, + AppContext appContext, + CoreLocalizationConstant coreLocalizationConstant, + MavenLocalizationConstant mavenLocalizationConstant, + PreferencesManager preferencesManager) { + super(mavenLocalizationConstant.mavenPreferencesTitle(), coreLocalizationConstant.extensionCategory()); + this.view = view; + this.appContext = appContext; + this.preferencesManager = preferencesManager; + + view.setDelegate(this); + } + + @Override + public boolean isDirty() { + return dirty; + } + + @Override + public void go(AcceptsOneWidget container) { + container.setWidget(view); + view.setSelectedShowArtifactIdCheckBox(getShowArtifactIdPreferenceValue()); + } + + @Override + public void storeChanges() { + preferencesManager.setValue(PREF_SHOW_ARTIFACT_ID, String.valueOf(showArtifactId)); + appContext.getWorkspaceRoot().synchronize(); + dirty = false; + } + + @Override + public void revertChanges() { + view.setSelectedShowArtifactIdCheckBox(getShowArtifactIdPreferenceValue()); + dirty = false; + } + + @Override + public void onArtifactIdCheckBoxValueChanged(boolean showArtifactId) { + this.showArtifactId = showArtifactId; + dirty = showArtifactId != getShowArtifactIdPreferenceValue(); + delegate.onDirtyChanged(); + } + + private boolean getShowArtifactIdPreferenceValue() { + return Boolean.valueOf(preferencesManager.getValue(PREF_SHOW_ARTIFACT_ID)); + } +} diff --git a/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/preference/MavenPreferenceView.java b/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/preference/MavenPreferenceView.java new file mode 100644 index 00000000000..390d5c012e3 --- /dev/null +++ b/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/preference/MavenPreferenceView.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.maven.client.preference; + +import com.google.inject.ImplementedBy; + +import org.eclipse.che.ide.api.mvp.View; + +/** + * View of Maven preferences page. + * + * @author Igor Vinokur + */ +@ImplementedBy(MavenPreferenceViewImpl.class) +public interface MavenPreferenceView extends View { + + /** + * Change the state of 'Show maven artifact id' checkbox. + * + * @param selected + * {@code true} to make the checkbox selected, {@code false} to deselect the checkbox + */ + void setSelectedShowArtifactIdCheckBox(boolean selected); + + interface ActionDelegate { + /** + * Called when the value of 'Show maven artifact id' checkbox is changed. + * + * @param value + * new value + */ + void onArtifactIdCheckBoxValueChanged(boolean value); + } +} diff --git a/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/preference/MavenPreferenceViewImpl.java b/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/preference/MavenPreferenceViewImpl.java new file mode 100644 index 00000000000..e2a4cf3b6b2 --- /dev/null +++ b/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/preference/MavenPreferenceViewImpl.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.maven.client.preference; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.uibinder.client.UiHandler; +import com.google.gwt.user.client.ui.CheckBox; +import com.google.gwt.user.client.ui.FlowPanel; +import com.google.gwt.user.client.ui.Widget; +import com.google.inject.Inject; +import com.google.inject.Singleton; + +import org.eclipse.che.plugin.maven.client.MavenLocalizationConstant; + +/** + * Implementation of {@link MavenPreferenceView}. + * + * @author Igor Vinokur + */ +@Singleton +public class MavenPreferenceViewImpl implements MavenPreferenceView { + + private static MavenPreferenceViewImplUiBinder uiBinder = GWT.create(MavenPreferenceViewImplUiBinder.class); + private final FlowPanel rootElement; + + @UiField(provided = true) + final MavenLocalizationConstant locale; + private ActionDelegate delegate; + + @UiField + CheckBox showArtifactId; + + @Inject + public MavenPreferenceViewImpl(MavenLocalizationConstant locale) { + this.locale = locale; + + rootElement = uiBinder.createAndBindUi(this); + } + + @Override + public void setDelegate(ActionDelegate delegate) { + this.delegate = delegate; + } + + @Override + public Widget asWidget() { + return rootElement; + } + + + @Override + public void setSelectedShowArtifactIdCheckBox(boolean selected) { + showArtifactId.setValue(selected); + } + + @UiHandler("showArtifactId") + void handleShowArtifactIdCheckBoxSelection(ClickEvent event) { + delegate.onArtifactIdCheckBoxValueChanged(showArtifactId.getValue()); + } + + interface MavenPreferenceViewImplUiBinder extends UiBinder { + } +} diff --git a/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/preference/MavenPreferenceViewImpl.ui.xml b/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/preference/MavenPreferenceViewImpl.ui.xml new file mode 100644 index 00000000000..b199c644062 --- /dev/null +++ b/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/preference/MavenPreferenceViewImpl.ui.xml @@ -0,0 +1,25 @@ + + + + + .main { + margin: 5px; + } + + + + + diff --git a/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/resource/MavenProjectInterceptor.java b/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/resource/MavenProjectInterceptor.java index d51174bbc80..e6826b60ece 100644 --- a/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/resource/MavenProjectInterceptor.java +++ b/plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/resource/MavenProjectInterceptor.java @@ -10,12 +10,16 @@ *******************************************************************************/ package org.eclipse.che.plugin.maven.client.resource; +import org.eclipse.che.ide.api.preferences.PreferencesManager; import org.eclipse.che.ide.api.resources.Project; import org.eclipse.che.ide.api.resources.Resource; import org.eclipse.che.ide.api.resources.ResourceInterceptor; import org.eclipse.che.ide.api.resources.marker.PresentableTextMarker; +import javax.inject.Inject; + import static com.google.common.base.Strings.isNullOrEmpty; +import static org.eclipse.che.plugin.maven.client.preference.MavenPreferencePresenter.PREF_SHOW_ARTIFACT_ID; import static org.eclipse.che.plugin.maven.shared.MavenAttributes.ARTIFACT_ID; import static org.eclipse.che.plugin.maven.shared.MavenAttributes.MAVEN_ID; @@ -27,9 +31,19 @@ */ public class MavenProjectInterceptor implements ResourceInterceptor { + private final PreferencesManager preferencesManager; + + @Inject + public MavenProjectInterceptor(PreferencesManager preferencesManager) { + this.preferencesManager = preferencesManager; + } + /** {@inheritDoc} */ @Override public void intercept(Resource resource) { + if (!Boolean.valueOf(preferencesManager.getValue(PREF_SHOW_ARTIFACT_ID))) { + return; + } if (resource.isProject() && ((Project)resource).isTypeOf(MAVEN_ID)) { final String artifact = ((Project)resource).getAttribute(ARTIFACT_ID); diff --git a/plugins/plugin-maven/che-plugin-maven-ide/src/main/resources/org/eclipse/che/plugin/maven/client/MavenLocalizationConstant.properties b/plugins/plugin-maven/che-plugin-maven-ide/src/main/resources/org/eclipse/che/plugin/maven/client/MavenLocalizationConstant.properties index 5ab977f5230..d135a32bf77 100644 --- a/plugins/plugin-maven/che-plugin-maven-ide/src/main/resources/org/eclipse/che/plugin/maven/client/MavenLocalizationConstant.properties +++ b/plugins/plugin-maven/che-plugin-maven-ide/src/main/resources/org/eclipse/che/plugin/maven/client/MavenLocalizationConstant.properties @@ -39,3 +39,7 @@ window.loader.title=Resolving dependencies ##### Wizard Maven Page ##### maven.page.errorDialog.title=Not valid Maven project maven.page.estimate.errorMessage=Source code not matches Maven project type requirements + +##### Preferences page ##### +maven.preferences.title=Maven +maven.preferences.show.artifact.id.checkbox.text=Show artifact id in project explorer