Skip to content

Commit b77aeff

Browse files
authored
CHE-5792: Add ability to adjust viewing 'maven module artifact id' in preferences window (eclipse-che#5849)
1 parent 03f7e01 commit b77aeff

8 files changed

Lines changed: 259 additions & 0 deletions

File tree

plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/MavenLocalizationConstant.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,11 @@ public interface MavenLocalizationConstant extends Messages {
6767

6868
@Key("maven.page.errorDialog.title")
6969
String mavenPageErrorDialogTitle();
70+
71+
/* Preferences page*/
72+
@Key("maven.preferences.title")
73+
String mavenPreferencesTitle();
74+
75+
@Key("maven.preferences.show.artifact.id.checkbox.text")
76+
String mavenPreferencesShowArtifactIdCheckboxText();
7077
}

plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/inject/MavenGinModule.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212

1313
import com.google.gwt.inject.client.AbstractGinModule;
1414
import com.google.gwt.inject.client.multibindings.GinMultibinder;
15+
1516
import org.eclipse.che.ide.api.command.CommandType;
1617
import org.eclipse.che.ide.api.extension.ExtensionGinModule;
18+
import org.eclipse.che.ide.api.preferences.PreferencePagePresenter;
1719
import org.eclipse.che.ide.api.project.type.wizard.ProjectWizardRegistrar;
1820
import org.eclipse.che.ide.api.resources.ResourceInterceptor;
1921
import org.eclipse.che.ide.project.ResolvingProjectStateHolder;
2022
import org.eclipse.che.plugin.maven.client.command.MavenCommandType;
23+
import org.eclipse.che.plugin.maven.client.preference.MavenPreferencePresenter;
2124
import org.eclipse.che.plugin.maven.client.project.ResolvingMavenProjectStateHolder;
2225
import org.eclipse.che.plugin.maven.client.resource.MavenProjectInterceptor;
2326
import org.eclipse.che.plugin.maven.client.resource.MavenSourceFolderInterceptor;
@@ -39,6 +42,8 @@ protected void configure() {
3942

4043
GinMultibinder.newSetBinder(binder(), CommandType.class).addBinding().to(MavenCommandType.class);
4144

45+
GinMultibinder.newSetBinder(binder(), PreferencePagePresenter.class).addBinding().to(MavenPreferencePresenter.class);
46+
4247
GinMultibinder.newSetBinder(binder(), ResourceInterceptor.class).addBinding().to(MavenSourceFolderInterceptor.class);
4348
GinMultibinder.newSetBinder(binder(), ResourceInterceptor.class).addBinding().to(PomInterceptor.class);
4449
GinMultibinder.newSetBinder(binder(), ResourceInterceptor.class).addBinding().to(MavenProjectInterceptor.class);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2012-2017 Codenvy, S.A.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Codenvy, S.A. - initial API and implementation
10+
*******************************************************************************/
11+
package org.eclipse.che.plugin.maven.client.preference;
12+
13+
import com.google.gwt.user.client.ui.AcceptsOneWidget;
14+
import com.google.inject.Inject;
15+
import com.google.inject.Singleton;
16+
17+
import org.eclipse.che.ide.CoreLocalizationConstant;
18+
import org.eclipse.che.ide.api.app.AppContext;
19+
import org.eclipse.che.ide.api.preferences.AbstractPreferencePagePresenter;
20+
import org.eclipse.che.ide.api.preferences.PreferencesManager;
21+
import org.eclipse.che.plugin.maven.client.MavenLocalizationConstant;
22+
23+
/**
24+
* Preference page presenter for Maven plugin.
25+
*
26+
* @author Igor Vinokur
27+
*/
28+
@Singleton
29+
public class MavenPreferencePresenter extends AbstractPreferencePagePresenter implements MavenPreferenceView.ActionDelegate {
30+
31+
public static final String PREF_SHOW_ARTIFACT_ID = "maven.artifact.in.project.explorer";
32+
33+
private final MavenPreferenceView view;
34+
private final AppContext appContext;
35+
private final PreferencesManager preferencesManager;
36+
37+
private boolean showArtifactId;
38+
private boolean dirty = false;
39+
40+
@Inject
41+
public MavenPreferencePresenter(MavenPreferenceView view,
42+
AppContext appContext,
43+
CoreLocalizationConstant coreLocalizationConstant,
44+
MavenLocalizationConstant mavenLocalizationConstant,
45+
PreferencesManager preferencesManager) {
46+
super(mavenLocalizationConstant.mavenPreferencesTitle(), coreLocalizationConstant.extensionCategory());
47+
this.view = view;
48+
this.appContext = appContext;
49+
this.preferencesManager = preferencesManager;
50+
51+
view.setDelegate(this);
52+
}
53+
54+
@Override
55+
public boolean isDirty() {
56+
return dirty;
57+
}
58+
59+
@Override
60+
public void go(AcceptsOneWidget container) {
61+
container.setWidget(view);
62+
view.setSelectedShowArtifactIdCheckBox(getShowArtifactIdPreferenceValue());
63+
}
64+
65+
@Override
66+
public void storeChanges() {
67+
preferencesManager.setValue(PREF_SHOW_ARTIFACT_ID, String.valueOf(showArtifactId));
68+
appContext.getWorkspaceRoot().synchronize();
69+
dirty = false;
70+
}
71+
72+
@Override
73+
public void revertChanges() {
74+
view.setSelectedShowArtifactIdCheckBox(getShowArtifactIdPreferenceValue());
75+
dirty = false;
76+
}
77+
78+
@Override
79+
public void onArtifactIdCheckBoxValueChanged(boolean showArtifactId) {
80+
this.showArtifactId = showArtifactId;
81+
dirty = showArtifactId != getShowArtifactIdPreferenceValue();
82+
delegate.onDirtyChanged();
83+
}
84+
85+
private boolean getShowArtifactIdPreferenceValue() {
86+
return Boolean.valueOf(preferencesManager.getValue(PREF_SHOW_ARTIFACT_ID));
87+
}
88+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2012-2017 Codenvy, S.A.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Codenvy, S.A. - initial API and implementation
10+
*******************************************************************************/
11+
package org.eclipse.che.plugin.maven.client.preference;
12+
13+
import com.google.inject.ImplementedBy;
14+
15+
import org.eclipse.che.ide.api.mvp.View;
16+
17+
/**
18+
* View of Maven preferences page.
19+
*
20+
* @author Igor Vinokur
21+
*/
22+
@ImplementedBy(MavenPreferenceViewImpl.class)
23+
public interface MavenPreferenceView extends View<MavenPreferenceView.ActionDelegate> {
24+
25+
/**
26+
* Change the state of 'Show maven artifact id' checkbox.
27+
*
28+
* @param selected
29+
* {@code true} to make the checkbox selected, {@code false} to deselect the checkbox
30+
*/
31+
void setSelectedShowArtifactIdCheckBox(boolean selected);
32+
33+
interface ActionDelegate {
34+
/**
35+
* Called when the value of 'Show maven artifact id' checkbox is changed.
36+
*
37+
* @param value
38+
* new value
39+
*/
40+
void onArtifactIdCheckBoxValueChanged(boolean value);
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2012-2017 Codenvy, S.A.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Codenvy, S.A. - initial API and implementation
10+
*******************************************************************************/
11+
package org.eclipse.che.plugin.maven.client.preference;
12+
13+
import com.google.gwt.core.client.GWT;
14+
import com.google.gwt.event.dom.client.ClickEvent;
15+
import com.google.gwt.uibinder.client.UiBinder;
16+
import com.google.gwt.uibinder.client.UiField;
17+
import com.google.gwt.uibinder.client.UiHandler;
18+
import com.google.gwt.user.client.ui.CheckBox;
19+
import com.google.gwt.user.client.ui.FlowPanel;
20+
import com.google.gwt.user.client.ui.Widget;
21+
import com.google.inject.Inject;
22+
import com.google.inject.Singleton;
23+
24+
import org.eclipse.che.plugin.maven.client.MavenLocalizationConstant;
25+
26+
/**
27+
* Implementation of {@link MavenPreferenceView}.
28+
*
29+
* @author Igor Vinokur
30+
*/
31+
@Singleton
32+
public class MavenPreferenceViewImpl implements MavenPreferenceView {
33+
34+
private static MavenPreferenceViewImplUiBinder uiBinder = GWT.create(MavenPreferenceViewImplUiBinder.class);
35+
private final FlowPanel rootElement;
36+
37+
@UiField(provided = true)
38+
final MavenLocalizationConstant locale;
39+
private ActionDelegate delegate;
40+
41+
@UiField
42+
CheckBox showArtifactId;
43+
44+
@Inject
45+
public MavenPreferenceViewImpl(MavenLocalizationConstant locale) {
46+
this.locale = locale;
47+
48+
rootElement = uiBinder.createAndBindUi(this);
49+
}
50+
51+
@Override
52+
public void setDelegate(ActionDelegate delegate) {
53+
this.delegate = delegate;
54+
}
55+
56+
@Override
57+
public Widget asWidget() {
58+
return rootElement;
59+
}
60+
61+
62+
@Override
63+
public void setSelectedShowArtifactIdCheckBox(boolean selected) {
64+
showArtifactId.setValue(selected);
65+
}
66+
67+
@UiHandler("showArtifactId")
68+
void handleShowArtifactIdCheckBoxSelection(ClickEvent event) {
69+
delegate.onArtifactIdCheckBoxValueChanged(showArtifactId.getValue());
70+
}
71+
72+
interface MavenPreferenceViewImplUiBinder extends UiBinder<FlowPanel, MavenPreferenceViewImpl> {
73+
}
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!--
2+
3+
Copyright (c) 2012-2017 Codenvy, S.A.
4+
All rights reserved. This program and the accompanying materials
5+
are made available under the terms of the Eclipse Public License v1.0
6+
which accompanies this distribution, and is available at
7+
http://www.eclipse.org/legal/epl-v10.html
8+
9+
Contributors:
10+
Codenvy, S.A. - initial API and implementation
11+
12+
-->
13+
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
14+
xmlns:g='urn:import:com.google.gwt.user.client.ui'>
15+
<ui:with field='locale' type='org.eclipse.che.plugin.maven.client.MavenLocalizationConstant'/>
16+
<ui:style>
17+
.main {
18+
margin: 5px;
19+
}
20+
</ui:style>
21+
<g:FlowPanel styleName="{style.main}">
22+
<g:CheckBox ui:field="showArtifactId" text="{locale.mavenPreferencesShowArtifactIdCheckboxText}"
23+
debugId="window-preferences-plugins-maven-showArtifactId"/>
24+
</g:FlowPanel>
25+
</ui:UiBinder>

plugins/plugin-maven/che-plugin-maven-ide/src/main/java/org/eclipse/che/plugin/maven/client/resource/MavenProjectInterceptor.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@
1010
*******************************************************************************/
1111
package org.eclipse.che.plugin.maven.client.resource;
1212

13+
import org.eclipse.che.ide.api.preferences.PreferencesManager;
1314
import org.eclipse.che.ide.api.resources.Project;
1415
import org.eclipse.che.ide.api.resources.Resource;
1516
import org.eclipse.che.ide.api.resources.ResourceInterceptor;
1617
import org.eclipse.che.ide.api.resources.marker.PresentableTextMarker;
1718

19+
import javax.inject.Inject;
20+
1821
import static com.google.common.base.Strings.isNullOrEmpty;
22+
import static org.eclipse.che.plugin.maven.client.preference.MavenPreferencePresenter.PREF_SHOW_ARTIFACT_ID;
1923
import static org.eclipse.che.plugin.maven.shared.MavenAttributes.ARTIFACT_ID;
2024
import static org.eclipse.che.plugin.maven.shared.MavenAttributes.MAVEN_ID;
2125

@@ -27,9 +31,19 @@
2731
*/
2832
public class MavenProjectInterceptor implements ResourceInterceptor {
2933

34+
private final PreferencesManager preferencesManager;
35+
36+
@Inject
37+
public MavenProjectInterceptor(PreferencesManager preferencesManager) {
38+
this.preferencesManager = preferencesManager;
39+
}
40+
3041
/** {@inheritDoc} */
3142
@Override
3243
public void intercept(Resource resource) {
44+
if (!Boolean.valueOf(preferencesManager.getValue(PREF_SHOW_ARTIFACT_ID))) {
45+
return;
46+
}
3347
if (resource.isProject() && ((Project)resource).isTypeOf(MAVEN_ID)) {
3448

3549
final String artifact = ((Project)resource).getAttribute(ARTIFACT_ID);

plugins/plugin-maven/che-plugin-maven-ide/src/main/resources/org/eclipse/che/plugin/maven/client/MavenLocalizationConstant.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@ window.loader.title=Resolving dependencies
3939
##### Wizard Maven Page #####
4040
maven.page.errorDialog.title=Not valid Maven project
4141
maven.page.estimate.errorMessage=Source code not matches Maven project type requirements
42+
43+
##### Preferences page #####
44+
maven.preferences.title=Maven
45+
maven.preferences.show.artifact.id.checkbox.text=Show artifact id in project explorer

0 commit comments

Comments
 (0)