Skip to content

Commit

Permalink
[JBIDE-22595] fixes according to comments in PR
Browse files Browse the repository at this point in the history
  • Loading branch information
adietish committed Jun 27, 2016
1 parent f8aa02e commit 3c941b7
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 37 deletions.
Expand Up @@ -59,6 +59,8 @@ public interface IConnection {

public void enablePromptCredentials(boolean enable);

public boolean isEnablePromptCredentials();

/**
* Returns true if and only if connections are equal and
* credentials like userName and password are equal.
Expand Down
Expand Up @@ -108,6 +108,11 @@ public boolean isRememberPassword() {
@Override
public void enablePromptCredentials(boolean enable) {
}

@Override
public boolean isEnablePromptCredentials() {
return false;
}

@Override
public IConnection clone() {
Expand Down
Expand Up @@ -54,7 +54,7 @@ public class ConnectionWizardPageModel extends ObservableUIPojo {
public static final String PROPERTY_USERDOCURL = "userdocUrl";
public static final String PROPERTY_HAS_DEFAULT_HOST = "hasDefaultHost";
private static final IStatus NOT_CONNECTED_STATUS = null;

/** the connection that the user wants to edit */
private IConnection selectedConnection;
/** the connection that this wizard operates on */
Expand All @@ -73,6 +73,7 @@ public class ConnectionWizardPageModel extends ObservableUIPojo {
private Collection<IConnection> allConnections;
private Class<? extends IConnection> connectionType;
private IConnectionAware<IConnection> wizardModel;
private boolean enablePromptCredentialsBackup = false;

protected ConnectionWizardPageModel(IConnection editedConnection, Collection<IConnection> allConnections,
Class<? extends IConnection> connectionType, boolean allowConnectionChange, IConnectionAware<IConnection> wizardModel) {
Expand Down Expand Up @@ -134,6 +135,7 @@ private void initConnection(IConnection editedConnection, Class<? extends IConne

private void initEditConnection(IConnection connection) {
this.selectedConnection = connection;
this.enablePromptCredentialsBackup = selectedConnection.isEnablePromptCredentials();
this.selectedConnection.enablePromptCredentials(false);
this.connectionFactory = connectionsFactory.getByConnection(connection.getClass());
this.host = connection.getHost();
Expand Down Expand Up @@ -474,7 +476,7 @@ public Collection<IConnectionFactory> getAllConnectionFactories() {
public void dispose() {
connectionsFactory.close();
if (this.selectedConnection != null) {
selectedConnection.enablePromptCredentials(true);
selectedConnection.enablePromptCredentials(enablePromptCredentialsBackup);
}
}

Expand Down
Expand Up @@ -177,26 +177,24 @@ public static ISelection getOpenShiftExplorerSelection() {
*/
public static <T extends IConnection> T getConnectionForExplorerSelection(Class<T> klass) {
ISelection selection = getOpenShiftExplorerSelection();
if(selection != null) {
if(selection != null
&& !selection.isEmpty()) {
T result = UIUtils.getFirstElement(selection, klass);
IViewPart part = getOpenShiftExplorer();
if(result == null
&& selection instanceof IStructuredSelection
&& part instanceof CommonNavigator) {
Object selected = ((IStructuredSelection)selection).getFirstElement();
IContentProvider provider = ((CommonNavigator) part).getCommonViewer().getContentProvider();
if(provider instanceof ITreeContentProvider) {
ITreeContentProvider tree = (ITreeContentProvider)provider;
while(selected != null && result == null) {
result = UIUtils.adapt(selected, klass);
selected = tree.getParent(selected);
}
if (selection != null
&& !selection.isEmpty()) {
T result = UIUtils.getFirstElement(selection, klass);
IViewPart part = getOpenShiftExplorer();
if (result == null
&& selection instanceof IStructuredSelection
&& part instanceof CommonNavigator) {
Object selected = ((IStructuredSelection) selection).getFirstElement();
IContentProvider provider = ((CommonNavigator) part).getCommonViewer().getContentProvider();
if (provider instanceof ITreeContentProvider) {
ITreeContentProvider tree = (ITreeContentProvider) provider;
while (selected != null && result == null) {
result = UIUtils.adapt(selected, klass);
selected = tree.getParent(selected);
}
}
return result;
}
return result;
}
return null;
}
Expand Down
Expand Up @@ -185,6 +185,11 @@ public void enablePromptCredentials(boolean enable) {
this.promptCredentialsEnabled = enable;
}

@Override
public boolean isEnablePromptCredentials() {
return promptCredentialsEnabled;
}

public String getAuthScheme() {
return org.apache.commons.lang.StringUtils.defaultIfBlank(this.authScheme, IAuthorizationContext.AUTHSCHEME_OAUTH);
}
Expand Down
Expand Up @@ -431,7 +431,7 @@ public static String getDeploymentConfigNameForPods(List<IPod> pods) {
.orElse(null);
}

public static com.openshift.restclient.model.IProject getProject(IResource resource) {
public static IProject getProject(IResource resource) {
IProject project = null;
if (resource instanceof IProject) {
project = (IProject) resource;
Expand Down
Expand Up @@ -181,6 +181,11 @@ public void enablePromptCredentials(boolean enable) {
this.promptPasswordEnabled = enable;
}

@Override
public boolean isEnablePromptCredentials() {
return promptPasswordEnabled;
}

public void setSSLCertificateCallback(ISSLCertificateCallback callback) {
this.sslCallback = callback;
}
Expand Down
Expand Up @@ -26,6 +26,7 @@
import org.eclipse.ui.handlers.HandlerUtil;
import org.jboss.tools.common.ui.WizardUtils;
import org.jboss.tools.openshift.core.connection.Connection;
import org.jboss.tools.openshift.core.connection.ConnectionsRegistryUtil;
import org.jboss.tools.openshift.internal.common.core.job.AbstractDelegatingMonitorJob;
import org.jboss.tools.openshift.internal.common.ui.utils.OpenShiftUIUtils;
import org.jboss.tools.openshift.internal.common.ui.utils.UIUtils;
Expand All @@ -46,14 +47,12 @@ public class DeployImageHandler extends AbstractHandler {
public Object execute(ExecutionEvent event) throws ExecutionException {
Connection connection = null;
IProject project = null;
// IWorkbenchWindow window = HandlerUtil.getActivePart(event).getSite().getWorkbenchWindow();
// ISelection selection = window.getSelectionService().getSelection();
ISelection selection = HandlerUtil.getCurrentSelection(event);
final IDockerImage image = UIUtils.getFirstElement(selection, IDockerImage.class);
if (image != null) {
selection = OpenShiftUIUtils.getOpenShiftExplorerSelection();
project = ResourceUtils.getProject(UIUtils.getFirstElement(selection, IResource.class));
connection = OpenShiftUIUtils.getConnectionForExplorerSelection(Connection.class);
connection = ConnectionsRegistryUtil.getConnectionFor(project);
}

if(connection == null) {
Expand Down
Expand Up @@ -62,7 +62,7 @@ public class ConnectionEditor extends BaseConnectionEditor {

private ComboViewer authTypeViewer;
private IObservableValue<Boolean> rememberTokenObservable;
private IObservableValue<IDetailView> detailViewObservable;
private IObservableValue<IDetailView> selectedDetailViewObservable;
private IObservableValue<String> authSchemeObservable;
private Binding selectedAuthTypeBinding;

Expand All @@ -77,17 +77,13 @@ public void setSelectedDetailView(IConnectionEditorDetailView view) {
this.selectedDetailView = view;
}

// public void setAuthScheme(String scheme) {
// detailViewObservable.setValue(detailViews.get(scheme));
// }

public void setSelectedConnection(IConnection conn) {
if(conn instanceof Connection) {
Connection connection = (Connection) conn;
detailViewObservable.setValue(detailViews.get(connection.getAuthScheme()));
selectedDetailViewObservable.setValue(detailViews.get(connection.getAuthScheme()));
} else {
rememberTokenObservable.setValue(Boolean.FALSE);
detailViewObservable.setValue(detailViews.get(IAuthorizationContext.AUTHSCHEME_OAUTH));
selectedDetailViewObservable.setValue(detailViews.get(IAuthorizationContext.AUTHSCHEME_OAUTH));
}

setDetailViewsConnection(conn);
Expand All @@ -102,7 +98,7 @@ private void setDetailViewsConnection(IConnection conn) {

private class ConnectionEditorStackedDetailViews extends AbstractStackedDetailViews{

public ConnectionEditorStackedDetailViews(IObservableValue<?> detailViewModel, Object context, Composite parent,
public ConnectionEditorStackedDetailViews(IObservableValue<IDetailView> detailViewModel, Object context, Composite parent,
DataBindingContext dbc) {
super(detailViewModel, context, parent, dbc);
}
Expand All @@ -120,7 +116,7 @@ public Composite createControls(Composite parent, ConnectionWizardPageModel page
GridLayoutFactory.fillDefaults()
.numColumns(2).margins(10, 10).spacing(10, 10).applyTo(composite);

this.detailViewObservable =
this.selectedDetailViewObservable =
BeanProperties.value(PROPERTY_SELECTED_DETAIL_VIEW, IConnectionEditorDetailView.class).observe(detailViewModel);
this.authSchemeObservable =
BeanProperties.value("authScheme", String.class).observe(detailViewModel);
Expand Down Expand Up @@ -155,7 +151,7 @@ public String getText(Object element) {
GridDataFactory.fillDefaults()
.align(SWT.FILL, SWT.FILL).span(3,1).applyTo(detailsContainer);
stackedViews = new ConnectionEditorStackedDetailViews(
detailViewObservable,
selectedDetailViewObservable,
pageModel,
detailsContainer,
dbc);
Expand Down Expand Up @@ -183,7 +179,7 @@ private void bindWidgetsToInternalModel(DataBindingContext dbc) {
.validatingAfterGet(
new IsNotNullValidator(
ValidationStatus.cancel("Please select an authorization protocol.")))
.to(detailViewObservable)
.to(selectedDetailViewObservable)
.in(dbc);
ControlDecorationSupport
.create(selectedAuthTypeBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
Expand Down
Expand Up @@ -352,8 +352,8 @@ public IConnection update(IConnection conn) {
@Override
public void run() {
connection.setAuthScheme(IAuthorizationContext.AUTHSCHEME_OAUTH);
connection.setToken((String) tokenObservable.getValue());
connection.setRememberToken((boolean) rememberTokenObservable.getValue());
connection.setToken(tokenObservable.getValue());
connection.setRememberToken(rememberTokenObservable.getValue());
}
});
return connection;
Expand Down
Expand Up @@ -11,6 +11,7 @@
package org.jboss.tools.openshift.internal.ui.wizard.deployimage;

import java.util.Collection;
import java.util.Comparator;
import java.util.List;

import org.eclipse.linuxtools.docker.core.IDockerConnection;
Expand Down Expand Up @@ -72,6 +73,8 @@ public interface IDeployImagePageModel extends IConnectionAware<Connection>{

void setProjects(List<IProject> projects);

void setProjectsComparator(Comparator<IProject> comparator);

/**
* The project to associate with this deployment
* @return
Expand Down
Expand Up @@ -206,7 +206,7 @@ public void should_disable_prompt_on_edited_connection() {

@Test
public void should_enable_prompt_on_edited_connection_when_disposing_model() {
// given prompt is disabled on edited connection
// given prompt is disabled once connection is being edited
verify(editedConnection).enablePromptCredentials(false);
// when
model.dispose();
Expand Down
Expand Up @@ -62,6 +62,11 @@ public void setPassword(String password) {
public void enablePromptCredentials(boolean enable) {
}

@Override
public boolean isEnablePromptCredentials() {
return false;
}

@Override
public boolean isRememberPassword() {
return false;
Expand Down

0 comments on commit 3c941b7

Please sign in to comment.