diff --git a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/parts/PartStack.java b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/parts/PartStack.java index 9979624da0..67a4e5d4ca 100644 --- a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/parts/PartStack.java +++ b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/parts/PartStack.java @@ -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(); diff --git a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/parts/PartStackStateChangedEvent.java b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/parts/PartStackStateChangedEvent.java index efd9576308..64b3dfb2c1 100644 --- a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/parts/PartStackStateChangedEvent.java +++ b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/parts/PartStackStateChangedEvent.java @@ -29,15 +29,35 @@ public class PartStackStateChangedEvent extends GwtEvent TYPE = new GwtEvent.Type(); 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 getAssociatedType() { return TYPE; diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/actions/common/HidePartAction.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/actions/common/HidePartAction.java index b80832c673..1df7a286bd 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/actions/common/HidePartAction.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/actions/common/HidePartAction.java @@ -50,7 +50,7 @@ public class HidePartAction extends BaseAction implements ActivePartChangedHandl @Override public void actionPerformed(ActionEvent e) { - activePartStack.hide(); + activePartStack.hide(true); } @Override diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/part/PartStackPresenter.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/part/PartStackPresenter.java index 2c7e05bfc4..528f1875d9 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/part/PartStackPresenter.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/part/PartStackPresenter.java @@ -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 */ diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/statepersistance/AppStateManager.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/statepersistance/AppStateManager.java index a323944489..facf9ce04e 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/statepersistance/AppStateManager.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/statepersistance/AppStateManager.java @@ -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; diff --git a/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/pom.xml b/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/pom.xml index ef1cffd4f4..09512bbaf2 100644 --- a/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/pom.xml +++ b/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/pom.xml @@ -29,10 +29,6 @@ com.google.guava guava - - com.google.gwt - gwt-elemental - com.google.gwt gwt-user diff --git a/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/ContributeMessages.java b/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/ContributeMessages.java index 946b6ad9c2..f935120bc8 100644 --- a/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/ContributeMessages.java +++ b/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/ContributeMessages.java @@ -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(); } diff --git a/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/ContributionMixinProvider.java b/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/ContributionMixinProvider.java index f160a44b0a..0f0eb6609f 100644 --- a/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/ContributionMixinProvider.java +++ b/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/ContributionMixinProvider.java @@ -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() { diff --git a/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/actions/ContributePartDisplayingModeAction.java b/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/actions/ContributePartDisplayingModeAction.java index 33537e3854..5315bd9b85 100644 --- a/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/actions/ContributePartDisplayingModeAction.java +++ b/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/actions/ContributePartDisplayingModeAction.java @@ -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) { diff --git a/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/inject/PullRequestGinModule.java b/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/inject/PullRequestGinModule.java index dec2b51d5c..ebc6d3bcd0 100644 --- a/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/inject/PullRequestGinModule.java +++ b/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/inject/PullRequestGinModule.java @@ -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); } } diff --git a/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/preference/ContributePreferencePresenter.java b/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/preference/ContributePreferencePresenter.java new file mode 100644 index 0000000000..eeeeb07d5a --- /dev/null +++ b/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/preference/ContributePreferencePresenter.java @@ -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); + } + } +} diff --git a/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/preference/ContributePreferenceView.java b/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/preference/ContributePreferenceView.java new file mode 100644 index 0000000000..07105a4b8c --- /dev/null +++ b/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/preference/ContributePreferenceView.java @@ -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 { + + /** Sets 'Activate by project selection' property */ + void setActivateByProjectSelection(boolean isActivate); + + interface ActionDelegate { + /** 'Activate by project selection' property is being changed */ + void onActivateByProjectSelectionChanged(boolean isActivated); + } +} diff --git a/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/preference/ContributePreferenceViewImpl.java b/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/preference/ContributePreferenceViewImpl.java new file mode 100644 index 0000000000..45dd4a8552 --- /dev/null +++ b/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/preference/ContributePreferenceViewImpl.java @@ -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 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 {} +} diff --git a/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/preference/ContributePreferenceViewImpl.ui.xml b/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/preference/ContributePreferenceViewImpl.ui.xml new file mode 100644 index 0000000000..9674742ed0 --- /dev/null +++ b/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/java/org/eclipse/che/plugin/pullrequest/client/preference/ContributePreferenceViewImpl.ui.xml @@ -0,0 +1,37 @@ + + + + + + .main { + width: 100%; + height: 25px; + margin-top: 5px; + margin-left: 5px; + } + .leftAlign { + float: left; + } + .rightAlign { + float: right; + } + + + + + + + + \ No newline at end of file diff --git a/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/resources/org/eclipse/che/plugin/pullrequest/client/ContributeMessages.properties b/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/resources/org/eclipse/che/plugin/pullrequest/client/ContributeMessages.properties index 3e7e7568f0..d0bab1ab8c 100644 --- a/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/resources/org/eclipse/che/plugin/pullrequest/client/ContributeMessages.properties +++ b/plugins/plugin-pullrequest-parent/che-plugin-pullrequest-ide/src/main/resources/org/eclipse/che/plugin/pullrequest/client/ContributeMessages.properties @@ -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 \ No newline at end of file +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