CHE-9484. Fix contribute part displaying at project selection
Signed-off-by: Roman Nikitenko <rnikiten@redhat.com>6.19.x
parent
9fa80210c6
commit
300b9fb81f
|
|
@ -104,9 +104,22 @@ public interface PartStack extends Presenter {
|
|||
/** Shows the part stack. */
|
||||
void show();
|
||||
|
||||
/** Hides the part stack. */
|
||||
/**
|
||||
* Hides the Part Stack. Use {@link #hide(boolean)} when hiding of the Part Stack is caused by
|
||||
* user action
|
||||
*/
|
||||
void hide();
|
||||
|
||||
/**
|
||||
* Hides the Part Stack.
|
||||
*
|
||||
* @param isUserInteraction pass {@code true} when hiding of the Part Stack is caused by user
|
||||
* action (user clicked 'Hide' button, for example) or {@code false} otherwise
|
||||
*/
|
||||
default void hide(boolean isUserInteraction) {
|
||||
hide();
|
||||
}
|
||||
|
||||
/** Maximizes the part stack. */
|
||||
void maximize();
|
||||
|
||||
|
|
|
|||
|
|
@ -29,15 +29,35 @@ public class PartStackStateChangedEvent extends GwtEvent<PartStackStateChangedEv
|
|||
public static final GwtEvent.Type<Handler> TYPE = new GwtEvent.Type<Handler>();
|
||||
|
||||
private PartStack partStack;
|
||||
private boolean isUserInteraction;
|
||||
|
||||
public PartStackStateChangedEvent(PartStack partStack) {
|
||||
this(partStack, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates event to notify Part Stack state is changed.
|
||||
*
|
||||
* @param isUserInteraction pass {@code true} when hiding of the Part Stack is caused by user
|
||||
* action (user clicked 'Hide' button, for example) or {@code false} otherwise
|
||||
*/
|
||||
public PartStackStateChangedEvent(PartStack partStack, boolean isUserInteraction) {
|
||||
this.partStack = partStack;
|
||||
this.isUserInteraction = isUserInteraction;
|
||||
}
|
||||
|
||||
public PartStack getPartStack() {
|
||||
return partStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} when hiding of the Part Stack is caused by user action (user clicked
|
||||
* 'Hide' button, for example) or {@code false} otherwise
|
||||
*/
|
||||
public boolean isUserInteraction() {
|
||||
return isUserInteraction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type<Handler> getAssociatedType() {
|
||||
return TYPE;
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class HidePartAction extends BaseAction implements ActivePartChangedHandl
|
|||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
activePartStack.hide();
|
||||
activePartStack.hide(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -238,15 +238,7 @@ public class PartStackPresenter
|
|||
workBenchPartController.setHidden(false);
|
||||
}
|
||||
|
||||
// Notify the part stack state has been changed.
|
||||
Scheduler.get()
|
||||
.scheduleDeferred(
|
||||
new Scheduler.ScheduledCommand() {
|
||||
@Override
|
||||
public void execute() {
|
||||
eventBus.fireEvent(new PartStackStateChangedEvent(PartStackPresenter.this));
|
||||
}
|
||||
});
|
||||
notifyPartStackStateChanged();
|
||||
|
||||
selectActiveTab(tab);
|
||||
}
|
||||
|
|
@ -321,7 +313,7 @@ public class PartStackPresenter
|
|||
|
||||
@Override
|
||||
public void onHide() {
|
||||
hide();
|
||||
hide(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -350,15 +342,7 @@ public class PartStackPresenter
|
|||
delegate.onMaximize(this);
|
||||
}
|
||||
|
||||
// Notify the part stack state has been changed.
|
||||
Scheduler.get()
|
||||
.scheduleDeferred(
|
||||
new Scheduler.ScheduledCommand() {
|
||||
@Override
|
||||
public void execute() {
|
||||
eventBus.fireEvent(new PartStackStateChangedEvent(PartStackPresenter.this));
|
||||
}
|
||||
});
|
||||
notifyPartStackStateChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -388,15 +372,7 @@ public class PartStackPresenter
|
|||
activeTab = null;
|
||||
activePart = null;
|
||||
|
||||
// Notify the part stack state has been changed.
|
||||
Scheduler.get()
|
||||
.scheduleDeferred(
|
||||
new Scheduler.ScheduledCommand() {
|
||||
@Override
|
||||
public void execute() {
|
||||
eventBus.fireEvent(new PartStackStateChangedEvent(PartStackPresenter.this));
|
||||
}
|
||||
});
|
||||
notifyPartStackStateChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -406,6 +382,11 @@ public class PartStackPresenter
|
|||
|
||||
@Override
|
||||
public void hide() {
|
||||
hide(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide(boolean isUserAction) {
|
||||
// Update the view state.
|
||||
view.setMaximized(false);
|
||||
|
||||
|
|
@ -435,15 +416,7 @@ public class PartStackPresenter
|
|||
activeTab = null;
|
||||
activePart = null;
|
||||
|
||||
// Notify the part stack state has been changed.
|
||||
Scheduler.get()
|
||||
.scheduleDeferred(
|
||||
new Scheduler.ScheduledCommand() {
|
||||
@Override
|
||||
public void execute() {
|
||||
eventBus.fireEvent(new PartStackStateChangedEvent(PartStackPresenter.this));
|
||||
}
|
||||
});
|
||||
notifyPartStackStateChanged(isUserAction);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -459,15 +432,7 @@ public class PartStackPresenter
|
|||
delegate.onRestore(this);
|
||||
}
|
||||
|
||||
// Notify the part stack state has been changed.
|
||||
Scheduler.get()
|
||||
.scheduleDeferred(
|
||||
new Scheduler.ScheduledCommand() {
|
||||
@Override
|
||||
public void execute() {
|
||||
eventBus.fireEvent(new PartStackStateChangedEvent(PartStackPresenter.this));
|
||||
}
|
||||
});
|
||||
notifyPartStackStateChanged();
|
||||
|
||||
if (activePart != null) {
|
||||
activePart.onOpen();
|
||||
|
|
@ -519,15 +484,7 @@ public class PartStackPresenter
|
|||
activeTab.select();
|
||||
}
|
||||
|
||||
// Notify the part stack state has been changed.
|
||||
Scheduler.get()
|
||||
.scheduleDeferred(
|
||||
new Scheduler.ScheduledCommand() {
|
||||
@Override
|
||||
public void execute() {
|
||||
eventBus.fireEvent(new PartStackStateChangedEvent(PartStackPresenter.this));
|
||||
}
|
||||
});
|
||||
notifyPartStackStateChanged();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
|
@ -557,6 +514,25 @@ public class PartStackPresenter
|
|||
partMenu.show(mouseX, mouseY);
|
||||
}
|
||||
|
||||
/** Notify the Part Stack state has been changed. */
|
||||
private void notifyPartStackStateChanged() {
|
||||
notifyPartStackStateChanged(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify the Part Stack state has been changed.
|
||||
*
|
||||
* @param isUserInteraction pass {@code true} when hiding of the Part Stack is caused by user
|
||||
* action (user clicked 'Hide' button, for example) or {@code false} otherwise
|
||||
*/
|
||||
private void notifyPartStackStateChanged(boolean isUserInteraction) {
|
||||
Scheduler.get()
|
||||
.scheduleDeferred(
|
||||
() ->
|
||||
eventBus.fireEvent(
|
||||
new PartStackStateChangedEvent(PartStackPresenter.this, isUserInteraction)));
|
||||
}
|
||||
|
||||
/** Handles PartStack actions */
|
||||
public interface PartStackEventHandler {
|
||||
/** PartStack is being clicked and requests Focus */
|
||||
|
|
|
|||
|
|
@ -149,10 +149,22 @@ public class AppStateManager {
|
|||
stateComponentRegistry.get().getComponentById(key);
|
||||
if (stateComponent.isPresent()) {
|
||||
StateComponent component = stateComponent.get();
|
||||
Log.debug(getClass(), "Restore state for the component ID: " + component.getId());
|
||||
String componentId = component.getId();
|
||||
Log.debug(getClass(), "Restore state for the component ID: " + componentId);
|
||||
sequentialRestore =
|
||||
sequentialRestore.thenPromise(
|
||||
ignored -> component.loadState(appState.getObject(key)));
|
||||
ignored ->
|
||||
component
|
||||
.loadState(appState.getObject(key))
|
||||
.catchError(
|
||||
arg -> {
|
||||
String error =
|
||||
"Error is happened at restoring state for the component "
|
||||
+ componentId
|
||||
+ ": "
|
||||
+ arg.getMessage();
|
||||
Log.error(getClass(), error);
|
||||
}));
|
||||
}
|
||||
}
|
||||
return sequentialRestore;
|
||||
|
|
|
|||
|
|
@ -29,10 +29,6 @@
|
|||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.gwt</groupId>
|
||||
<artifactId>gwt-elemental</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.gwt</groupId>
|
||||
<artifactId>gwt-user</artifactId>
|
||||
|
|
|
|||
|
|
@ -278,4 +278,19 @@ public interface ContributeMessages extends Messages {
|
|||
|
||||
@Key("action.switch.contribute.part.displaying.description")
|
||||
String switchContributePartDisplayingDescription();
|
||||
|
||||
/*
|
||||
* Contribute part preferences
|
||||
*/
|
||||
@Key("contribute.preferences.title")
|
||||
String contributePreferencesTitle();
|
||||
|
||||
@Key("contribute.preferences.category")
|
||||
String contributePreferencesCategory();
|
||||
|
||||
@Key("contribute.preferences.activateByProjectSelectionLabel")
|
||||
String contributePreferencesActivateByProjectSelectionLabel();
|
||||
|
||||
@Key("contribute.preferences.notification.activatePart.text")
|
||||
String contributePreferencesNotificationActivatePartText();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,11 +10,16 @@
|
|||
*/
|
||||
package org.eclipse.che.plugin.pullrequest.client;
|
||||
|
||||
import static com.google.common.base.Strings.isNullOrEmpty;
|
||||
import static java.lang.Boolean.parseBoolean;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.eclipse.che.api.core.model.workspace.WorkspaceStatus.RUNNING;
|
||||
import static org.eclipse.che.ide.api.constraints.Constraints.FIRST;
|
||||
import static org.eclipse.che.ide.api.parts.PartStack.State.HIDDEN;
|
||||
import static org.eclipse.che.ide.api.parts.PartStack.State.MINIMIZED;
|
||||
import static org.eclipse.che.ide.api.parts.PartStack.State.NORMAL;
|
||||
import static org.eclipse.che.ide.api.parts.PartStackType.TOOLING;
|
||||
import static org.eclipse.che.ide.statepersistance.AppStateConstants.HIDDEN_STATE;
|
||||
import static org.eclipse.che.plugin.pullrequest.client.preference.ContributePreferencePresenter.ACTIVATE_BY_PROJECT_SELECTION;
|
||||
import static org.eclipse.che.plugin.pullrequest.shared.ContributionProjectTypeConstants.CONTRIBUTE_TO_BRANCH_VARIABLE_NAME;
|
||||
import static org.eclipse.che.plugin.pullrequest.shared.ContributionProjectTypeConstants.CONTRIBUTION_PROJECT_TYPE_ID;
|
||||
|
||||
|
|
@ -23,7 +28,6 @@ import com.google.inject.Inject;
|
|||
import com.google.inject.Singleton;
|
||||
import com.google.web.bindery.event.shared.EventBus;
|
||||
import com.google.web.bindery.event.shared.HandlerRegistration;
|
||||
import elemental.json.JsonObject;
|
||||
import org.eclipse.che.api.core.model.workspace.WorkspaceStatus;
|
||||
import org.eclipse.che.api.promises.client.Promise;
|
||||
import org.eclipse.che.api.promises.client.PromiseProvider;
|
||||
|
|
@ -34,6 +38,7 @@ import org.eclipse.che.ide.api.parts.PartStack;
|
|||
import org.eclipse.che.ide.api.parts.PartStack.State;
|
||||
import org.eclipse.che.ide.api.parts.PartStackStateChangedEvent;
|
||||
import org.eclipse.che.ide.api.parts.WorkspaceAgent;
|
||||
import org.eclipse.che.ide.api.preferences.PreferencesManager;
|
||||
import org.eclipse.che.ide.api.project.MutableProjectConfig;
|
||||
import org.eclipse.che.ide.api.resources.Project;
|
||||
import org.eclipse.che.ide.api.resources.Resource;
|
||||
|
|
@ -41,7 +46,6 @@ import org.eclipse.che.ide.api.selection.Selection;
|
|||
import org.eclipse.che.ide.api.selection.SelectionChangedEvent;
|
||||
import org.eclipse.che.ide.api.workspace.WorkspaceReadyEvent;
|
||||
import org.eclipse.che.ide.api.workspace.event.WorkspaceStoppedEvent;
|
||||
import org.eclipse.che.ide.statepersistance.AppStateManager;
|
||||
import org.eclipse.che.ide.ui.smartTree.data.HasDataObject;
|
||||
import org.eclipse.che.ide.util.loging.Log;
|
||||
import org.eclipse.che.plugin.pullrequest.client.parts.contribute.ContributePartPresenter;
|
||||
|
|
@ -64,7 +68,7 @@ public class ContributionMixinProvider {
|
|||
private final EventBus eventBus;
|
||||
private final AppContext appContext;
|
||||
private final WorkspaceAgent workspaceAgent;
|
||||
private final AppStateManager appStateManager;
|
||||
private final PreferencesManager preferencesManager;
|
||||
private final ContributePartPresenter contributePart;
|
||||
private final WorkflowExecutor workflowExecutor;
|
||||
private final VcsServiceProvider vcsServiceProvider;
|
||||
|
|
@ -81,7 +85,7 @@ public class ContributionMixinProvider {
|
|||
EventBus eventBus,
|
||||
AppContext appContext,
|
||||
WorkspaceAgent workspaceAgent,
|
||||
AppStateManager appStateManager,
|
||||
PreferencesManager preferencesManager,
|
||||
ContributePartPresenter contributePart,
|
||||
WorkflowExecutor workflowExecutor,
|
||||
VcsServiceProvider vcsServiceProvider,
|
||||
|
|
@ -91,7 +95,7 @@ public class ContributionMixinProvider {
|
|||
this.eventBus = eventBus;
|
||||
this.appContext = appContext;
|
||||
this.workspaceAgent = workspaceAgent;
|
||||
this.appStateManager = appStateManager;
|
||||
this.preferencesManager = preferencesManager;
|
||||
this.contributePart = contributePart;
|
||||
this.workflowExecutor = workflowExecutor;
|
||||
this.vcsServiceProvider = vcsServiceProvider;
|
||||
|
|
@ -112,7 +116,12 @@ public class ContributionMixinProvider {
|
|||
|
||||
private void onPartStackStateChanged(PartStackStateChangedEvent event) {
|
||||
PartStack toolingPartStack = workspaceAgent.getPartStack(TOOLING);
|
||||
if (event.getPartStack() != toolingPartStack || isPartStackHidden(toolingPartStack)) {
|
||||
if (event.getPartStack() != toolingPartStack) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isPartStackHidden(toolingPartStack)) {
|
||||
invalidateContext(lastSelected);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -124,9 +133,7 @@ public class ContributionMixinProvider {
|
|||
|
||||
private void onSelectionChanged(Selection<?> selection) {
|
||||
WorkspaceStatus workspaceStatus = appContext.getWorkspace().getStatus();
|
||||
if (RUNNING != workspaceStatus
|
||||
|| !isSupportedSelection(selection)
|
||||
|| isContributePartHiddenByUser()) {
|
||||
if (RUNNING != workspaceStatus || !isSupportedSelection(selection) || !isActivationAllowed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -250,7 +257,7 @@ public class ContributionMixinProvider {
|
|||
|
||||
private boolean isPartStackHidden(PartStack partStack) {
|
||||
State partStackState = partStack.getPartStackState();
|
||||
return partStackState == State.HIDDEN || partStackState == State.MINIMIZED;
|
||||
return partStackState == HIDDEN || partStackState == MINIMIZED;
|
||||
}
|
||||
|
||||
private boolean isSupportedSelection(Selection<?> selection) {
|
||||
|
|
@ -268,13 +275,18 @@ public class ContributionMixinProvider {
|
|||
return headElem == null || isResourceSelection || isHasDataWithResource;
|
||||
}
|
||||
|
||||
private boolean isContributePartHiddenByUser() {
|
||||
JsonObject toolingPartStackState = appStateManager.getStateFor(TOOLING);
|
||||
if (toolingPartStackState != null && toolingPartStackState.hasKey(HIDDEN_STATE)) {
|
||||
return toolingPartStackState.getBoolean(HIDDEN_STATE);
|
||||
private boolean isActivationAllowed() {
|
||||
State toolingPartStackState = workspaceAgent.getPartStack(TOOLING).getPartStackState();
|
||||
if (MINIMIZED == toolingPartStackState) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
if (NORMAL == toolingPartStackState) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String preference = preferencesManager.getValue(ACTIVATE_BY_PROJECT_SELECTION);
|
||||
return isNullOrEmpty(preference) || parseBoolean(preference);
|
||||
}
|
||||
|
||||
private void subscribeToSelectionChangedEvent() {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import org.eclipse.che.ide.api.action.ActionEvent;
|
|||
import org.eclipse.che.ide.api.editor.EditorAgent;
|
||||
import org.eclipse.che.ide.api.editor.EditorPartPresenter;
|
||||
import org.eclipse.che.ide.api.parts.PartPresenter;
|
||||
import org.eclipse.che.ide.api.parts.PartStack;
|
||||
import org.eclipse.che.ide.api.parts.WorkspaceAgent;
|
||||
import org.eclipse.che.plugin.pullrequest.client.ContributeMessages;
|
||||
import org.eclipse.che.plugin.pullrequest.client.ContributeResources;
|
||||
|
|
@ -66,8 +67,9 @@ public class ContributePartDisplayingModeAction extends AbstractPerspectiveActio
|
|||
public void actionPerformed(ActionEvent e) {
|
||||
ContributePartPresenter contributePartPresenter = contributePartPresenterProvider.get();
|
||||
PartPresenter activePart = workspaceAgent.getActivePart();
|
||||
if (activePart != null && activePart instanceof ContributePartPresenter) {
|
||||
workspaceAgent.hidePart(contributePartPresenter);
|
||||
if (activePart instanceof ContributePartPresenter) {
|
||||
PartStack toolingPartStack = workspaceAgent.getPartStack(TOOLING);
|
||||
toolingPartStack.hide(true);
|
||||
|
||||
EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
|
||||
if (activeEditor != null) {
|
||||
|
|
|
|||
|
|
@ -12,12 +12,15 @@ package org.eclipse.che.plugin.pullrequest.client.inject;
|
|||
|
||||
import com.google.gwt.inject.client.AbstractGinModule;
|
||||
import com.google.gwt.inject.client.assistedinject.GinFactoryModuleBuilder;
|
||||
import com.google.gwt.inject.client.multibindings.GinMultibinder;
|
||||
import javax.inject.Singleton;
|
||||
import org.eclipse.che.ide.api.extension.ExtensionGinModule;
|
||||
import org.eclipse.che.ide.api.preferences.PreferencePagePresenter;
|
||||
import org.eclipse.che.plugin.pullrequest.client.dialogs.commit.CommitView;
|
||||
import org.eclipse.che.plugin.pullrequest.client.dialogs.commit.CommitViewImpl;
|
||||
import org.eclipse.che.plugin.pullrequest.client.parts.contribute.ContributePartView;
|
||||
import org.eclipse.che.plugin.pullrequest.client.parts.contribute.ContributePartViewImpl;
|
||||
import org.eclipse.che.plugin.pullrequest.client.preference.ContributePreferencePresenter;
|
||||
import org.eclipse.che.plugin.pullrequest.client.steps.AddForkRemoteStepFactory;
|
||||
import org.eclipse.che.plugin.pullrequest.client.steps.PushBranchOnForkStep;
|
||||
import org.eclipse.che.plugin.pullrequest.client.steps.PushBranchStepFactory;
|
||||
|
|
@ -43,5 +46,8 @@ public class PullRequestGinModule extends AbstractGinModule {
|
|||
install(new GinFactoryModuleBuilder().build(WaitForkOnRemoteStepFactory.class));
|
||||
install(new GinFactoryModuleBuilder().build(PushBranchStepFactory.class));
|
||||
install(new GinFactoryModuleBuilder().build(AddForkRemoteStepFactory.class));
|
||||
GinMultibinder.newSetBinder(binder(), PreferencePagePresenter.class)
|
||||
.addBinding()
|
||||
.to(ContributePreferencePresenter.class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,142 @@
|
|||
/*
|
||||
* Copyright (c) 2012-2018 Red Hat, Inc.
|
||||
* 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:
|
||||
* Red Hat, Inc. - initial API and implementation
|
||||
*/
|
||||
package org.eclipse.che.plugin.pullrequest.client.preference;
|
||||
|
||||
import static com.google.common.base.Strings.isNullOrEmpty;
|
||||
import static java.lang.Boolean.parseBoolean;
|
||||
import static java.lang.String.valueOf;
|
||||
import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.EMERGE_MODE;
|
||||
import static org.eclipse.che.ide.api.notification.StatusNotification.Status.SUCCESS;
|
||||
import static org.eclipse.che.ide.api.parts.PartStack.State.HIDDEN;
|
||||
import static org.eclipse.che.ide.api.parts.PartStackType.TOOLING;
|
||||
|
||||
import com.google.gwt.user.client.ui.AcceptsOneWidget;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.web.bindery.event.shared.EventBus;
|
||||
import org.eclipse.che.ide.api.notification.NotificationManager;
|
||||
import org.eclipse.che.ide.api.parts.PartStack;
|
||||
import org.eclipse.che.ide.api.parts.PartStackStateChangedEvent;
|
||||
import org.eclipse.che.ide.api.parts.WorkspaceAgent;
|
||||
import org.eclipse.che.ide.api.preferences.AbstractPreferencePagePresenter;
|
||||
import org.eclipse.che.ide.api.preferences.PreferencesManager;
|
||||
import org.eclipse.che.ide.bootstrap.BasicIDEInitializedEvent;
|
||||
import org.eclipse.che.plugin.pullrequest.client.ContributeMessages;
|
||||
|
||||
/**
|
||||
* Preference page presenter for the Contribute Part.
|
||||
*
|
||||
* @author Roman Nikitenko
|
||||
*/
|
||||
@Singleton
|
||||
public class ContributePreferencePresenter extends AbstractPreferencePagePresenter
|
||||
implements ContributePreferenceView.ActionDelegate, PartStackStateChangedEvent.Handler {
|
||||
public static final String ACTIVATE_BY_PROJECT_SELECTION =
|
||||
"git.contribute.activate.projectSelection";
|
||||
|
||||
private ContributePreferenceView view;
|
||||
private ContributeMessages localizationConstants;
|
||||
private PreferencesManager preferencesManager;
|
||||
|
||||
private PartStack toolingPartStack;
|
||||
private NotificationManager notificationManager;
|
||||
private boolean isActivateByProjectSelection;
|
||||
|
||||
@Inject
|
||||
public ContributePreferencePresenter(
|
||||
EventBus eventBus,
|
||||
WorkspaceAgent workspaceAgent,
|
||||
ContributePreferenceView view,
|
||||
ContributeMessages localizationConstants,
|
||||
PreferencesManager preferencesManager,
|
||||
NotificationManager notificationManager) {
|
||||
super(
|
||||
localizationConstants.contributePreferencesTitle(),
|
||||
localizationConstants.contributePreferencesCategory());
|
||||
|
||||
this.view = view;
|
||||
this.localizationConstants = localizationConstants;
|
||||
this.preferencesManager = preferencesManager;
|
||||
this.toolingPartStack = workspaceAgent.getPartStack(TOOLING);
|
||||
this.notificationManager = notificationManager;
|
||||
|
||||
view.setDelegate(this);
|
||||
eventBus.addHandler(PartStackStateChangedEvent.TYPE, this);
|
||||
eventBus.addHandler(BasicIDEInitializedEvent.TYPE, e -> init());
|
||||
}
|
||||
|
||||
private void init() {
|
||||
String preference = preferencesManager.getValue(ACTIVATE_BY_PROJECT_SELECTION);
|
||||
if (isNullOrEmpty(preference)) {
|
||||
preference = "true";
|
||||
preferencesManager.setValue(ACTIVATE_BY_PROJECT_SELECTION, preference);
|
||||
}
|
||||
|
||||
isActivateByProjectSelection = parseBoolean(preference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirty() {
|
||||
String preference = preferencesManager.getValue(ACTIVATE_BY_PROJECT_SELECTION);
|
||||
boolean storedValue = isNullOrEmpty(preference) || parseBoolean(preference);
|
||||
|
||||
return isActivateByProjectSelection != storedValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void go(AcceptsOneWidget container) {
|
||||
container.setWidget(view);
|
||||
|
||||
view.setActivateByProjectSelection(isActivateByProjectSelection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storeChanges() {
|
||||
preferencesManager.setValue(
|
||||
ACTIVATE_BY_PROJECT_SELECTION, valueOf(isActivateByProjectSelection));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void revertChanges() {
|
||||
boolean storedValue = parseBoolean(preferencesManager.getValue(ACTIVATE_BY_PROJECT_SELECTION));
|
||||
|
||||
isActivateByProjectSelection = storedValue;
|
||||
view.setActivateByProjectSelection(storedValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivateByProjectSelectionChanged(boolean isActivated) {
|
||||
isActivateByProjectSelection = isActivated;
|
||||
delegate.onDirtyChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPartStackStateChanged(PartStackStateChangedEvent event) {
|
||||
if (!isActivateByProjectSelection || !event.isUserInteraction()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (toolingPartStack != null
|
||||
&& toolingPartStack.equals(event.getPartStack())
|
||||
&& toolingPartStack.getPartStackState() == HIDDEN) {
|
||||
isActivateByProjectSelection = false;
|
||||
view.setActivateByProjectSelection(false);
|
||||
|
||||
preferencesManager.setValue(ACTIVATE_BY_PROJECT_SELECTION, "false");
|
||||
preferencesManager.flushPreferences();
|
||||
notificationManager.notify(
|
||||
"",
|
||||
localizationConstants.contributePreferencesNotificationActivatePartText(),
|
||||
SUCCESS,
|
||||
EMERGE_MODE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2012-2018 Red Hat, Inc.
|
||||
* 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:
|
||||
* Red Hat, Inc. - initial API and implementation
|
||||
*/
|
||||
package org.eclipse.che.plugin.pullrequest.client.preference;
|
||||
|
||||
import com.google.inject.ImplementedBy;
|
||||
import org.eclipse.che.ide.api.mvp.View;
|
||||
|
||||
/**
|
||||
* View interface for the Contribute Part preference page.
|
||||
*
|
||||
* @author Roman Nikitenko
|
||||
*/
|
||||
@ImplementedBy(ContributePreferenceViewImpl.class)
|
||||
public interface ContributePreferenceView extends View<ContributePreferenceView.ActionDelegate> {
|
||||
|
||||
/** Sets 'Activate by project selection' property */
|
||||
void setActivateByProjectSelection(boolean isActivate);
|
||||
|
||||
interface ActionDelegate {
|
||||
/** 'Activate by project selection' property is being changed */
|
||||
void onActivateByProjectSelectionChanged(boolean isActivated);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2012-2018 Red Hat, Inc.
|
||||
* 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:
|
||||
* Red Hat, Inc. - initial API and implementation
|
||||
*/
|
||||
package org.eclipse.che.plugin.pullrequest.client.preference;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
||||
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;
|
||||
|
||||
/** @author Roman Nikitenko */
|
||||
@Singleton
|
||||
public class ContributePreferenceViewImpl implements ContributePreferenceView {
|
||||
private static ContributePreferenceViewImplUiBinder ourUiBinder =
|
||||
GWT.create(ContributePreferenceViewImplUiBinder.class);
|
||||
|
||||
@UiField CheckBox activateByProjectSelection;
|
||||
private ActionDelegate delegate;
|
||||
private final FlowPanel rootElement;
|
||||
|
||||
@Inject
|
||||
public ContributePreferenceViewImpl() {
|
||||
rootElement = ourUiBinder.createAndBindUi(this);
|
||||
}
|
||||
|
||||
@UiHandler("activateByProjectSelection")
|
||||
void handleActivateByProjectSelection(ValueChangeEvent<Boolean> event) {
|
||||
delegate.onActivateByProjectSelectionChanged(event.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActivateByProjectSelection(boolean isActivate) {
|
||||
activateByProjectSelection.setValue(isActivate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDelegate(ActionDelegate delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Widget asWidget() {
|
||||
return rootElement;
|
||||
}
|
||||
|
||||
interface ContributePreferenceViewImplUiBinder
|
||||
extends UiBinder<FlowPanel, ContributePreferenceViewImpl> {}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
<!--
|
||||
|
||||
Copyright (c) 2012-2018 Red Hat, Inc.
|
||||
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:
|
||||
Red Hat, Inc. - 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 type="org.eclipse.che.plugin.pullrequest.client.ContributeMessages" field="localizationConstants"/>
|
||||
<ui:style>
|
||||
.main {
|
||||
width: 100%;
|
||||
height: 25px;
|
||||
margin-top: 5px;
|
||||
margin-left: 5px;
|
||||
}
|
||||
.leftAlign {
|
||||
float: left;
|
||||
}
|
||||
.rightAlign {
|
||||
float: right;
|
||||
}
|
||||
</ui:style>
|
||||
|
||||
<g:FlowPanel addStyleNames="{style.main}">
|
||||
<g:Label text="{localizationConstants.contributePreferencesActivateByProjectSelectionLabel}" addStyleNames="{style.leftAlign}"/>
|
||||
<g:CheckBox ui:field="activateByProjectSelection" debugId="preferences-git-contribute-activateByProjectSelection" addStyleNames="{style.rightAlign}"/>
|
||||
</g:FlowPanel>
|
||||
|
||||
</ui:UiBinder>
|
||||
|
|
@ -160,4 +160,12 @@ failed.to.apply.vcs.mixin=Failed to apply mixin to project: {0}. Cause: {1}
|
|||
# Switching Contribute Part displaying mode
|
||||
#
|
||||
action.switch.contribute.part.displaying.title=Contribute
|
||||
action.switch.contribute.part.displaying.description=Switch Contribute part displaying mode
|
||||
action.switch.contribute.part.displaying.description=Switch Contribute part displaying mode
|
||||
|
||||
#
|
||||
# Contribute Part Preferences
|
||||
#
|
||||
contribute.preferences.title=Contribute
|
||||
contribute.preferences.category=Git
|
||||
contribute.preferences.activateByProjectSelectionLabel=Activate Contribute Panel by clicking on a project
|
||||
contribute.preferences.notification.activatePart.text=To activate Contribute Panel by clicking on a project go to Profile -> Preferences -> Git -> Contribute
|
||||
|
|
|
|||
Loading…
Reference in New Issue