Skip to content

Commit

Permalink
CHE-5792: Add ability to adjust viewing 'maven module artifact id' in…
Browse files Browse the repository at this point in the history
… preferences window (eclipse-che#5849)
  • Loading branch information
vinokurig committed Aug 14, 2017
1 parent 03f7e01 commit b77aeff
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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<MavenPreferenceView.ActionDelegate> {

/**
* 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);
}
}
Original file line number Diff line number Diff line change
@@ -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<FlowPanel, MavenPreferenceViewImpl> {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
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
-->
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'>
<ui:with field='locale' type='org.eclipse.che.plugin.maven.client.MavenLocalizationConstant'/>
<ui:style>
.main {
margin: 5px;
}
</ui:style>
<g:FlowPanel styleName="{style.main}">
<g:CheckBox ui:field="showArtifactId" text="{locale.mavenPreferencesShowArtifactIdCheckboxText}"
debugId="window-preferences-plugins-maven-showArtifactId"/>
</g:FlowPanel>
</ui:UiBinder>
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b77aeff

Please sign in to comment.