Skip to content

Commit

Permalink
JBIDE-21732 Server Adapter: Improve routing selection group in New Op…
Browse files Browse the repository at this point in the history
…enShift Server adapter wizard
  • Loading branch information
scabanovich authored and adietish committed Feb 26, 2016
1 parent d97616d commit 7a2589b
Show file tree
Hide file tree
Showing 6 changed files with 344 additions and 178 deletions.
@@ -0,0 +1,179 @@
/*******************************************************************************
* Copyright (c) 2016 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is 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.jboss.tools.openshift.internal.common.ui;

import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.conversion.Converter;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.databinding.fieldassist.ControlDecorationSupport;
import org.eclipse.jface.databinding.swt.ISWTObservableValue;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.fieldassist.AutoCompleteField;
import org.eclipse.jface.fieldassist.ControlDecoration;
import org.eclipse.jface.fieldassist.FieldDecoration;
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
import org.eclipse.jface.fieldassist.TextContentAdapter;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.jboss.tools.common.ui.databinding.ValueBindingBuilder;
import org.jboss.tools.openshift.common.core.utils.ProjectUtils;
import org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater;

public class SelectProjectComponentBuilder {
String textLabel = "Use existing workspace project:";
String browseLabel = "Browse...";
String errorText = "Select an existing project";
int hSpan = 1;

IObservableValue eclipseProjectObservable;
SelectionListener selectionListener;

ISWTObservableValue projectNameTextObservable;

public SelectProjectComponentBuilder() {}

public void build(Composite container, DataBindingContext dbc) {
Label existingProjectLabel = new Label(container, SWT.NONE);
existingProjectLabel.setText("Eclipse Project: ");
GridDataFactory.fillDefaults()
.align(SWT.FILL, SWT.CENTER)
.applyTo(existingProjectLabel);

final Text existingProjectNameText = new Text(container, SWT.BORDER);
GridDataFactory.fillDefaults()
.align(SWT.FILL, SWT.CENTER)
.span(2,1).align(SWT.FILL, SWT.CENTER).grab(true, false)
.applyTo(existingProjectNameText);

projectNameTextObservable = WidgetProperties.text(SWT.Modify).observe(existingProjectNameText);

Binding eclipseProjectBinding = ValueBindingBuilder
.bind(projectNameTextObservable)
.validatingAfterConvert(new IValidator() {
@Override
public IStatus validate(Object value) {
if(value instanceof String) {
return ValidationStatus.ok();
} else if(value == null) {
return ValidationStatus.error("Select an existing project");
}
return ValidationStatus.ok();
}
})
.converting(new Converter(String.class, IProject.class) {
@Override
public Object convert(Object fromObject) {
String name = (String)fromObject;
return ProjectUtils.getProject(name);
}
})
.to(eclipseProjectObservable)
.converting(new Converter(IProject.class, String.class) {

@Override
public Object convert(Object fromObject) {
return fromObject == null ? "" : ((IProject)fromObject).getName();
}
})
.in(dbc);
ControlDecorationSupport.create(
eclipseProjectBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));

// project name content assist
ControlDecoration dec = new ControlDecoration(existingProjectNameText, SWT.TOP | SWT.RIGHT);

FieldDecoration contentProposalFieldIndicator =
FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
dec.setImage(contentProposalFieldIndicator.getImage());
dec.setDescriptionText("Auto-completion is enabled when you start typing a project name.");
dec.setShowOnlyOnFocus(true);

new AutoCompleteField(existingProjectNameText, new TextContentAdapter(), ProjectUtils.getAllAccessibleProjectNames());

// browse projects
Button browseProjectsButton = new Button(container, SWT.NONE);
browseProjectsButton.setText("Browse...");
GridDataFactory.fillDefaults()
.align(SWT.LEFT, SWT.CENTER)
.hint(100, SWT.DEFAULT)
.grab(false, false)
.applyTo(browseProjectsButton);
browseProjectsButton.addSelectionListener(selectionListener);
}

/**
* Set value of label at text input. Has only effect if called before build().
*
* @param label
* @return
*/
public SelectProjectComponentBuilder setTextLabel(String label) {
textLabel = label;
return this;
}

/**
* Set value of model observable. Has only effect if called before build().
*
* @param label
* @return
*/
public SelectProjectComponentBuilder setEclipseProjectObservable(IObservableValue eclipseProjectObservable) {
this.eclipseProjectObservable = eclipseProjectObservable;
return this;
}

/**
* Set number of columns in the grid to take by text input.
* Grid needs one column for label, hSpan columns for text input, and one column for browse button.
* Has only effect if called before build().
*
* @param label
* @return
*/
public SelectProjectComponentBuilder setHorisontalSpan(int hSpan) {
this.hSpan = hSpan;
return this;
}

/**
* Set selection listener that will run a customized dialog and consume selected project.
* Has only effect if called before build().
*
* @param label
* @return
*/
public SelectProjectComponentBuilder setSelectionListener(SelectionListener listener) {
selectionListener = listener;
return this;
}

/**
* Returns swt observable for text input. Has only effect if called after build().
*
* @param label
* @return
*/
public ISWTObservableValue getProjectNameTextObservable() {
return projectNameTextObservable;
}

}
@@ -0,0 +1,78 @@
/*******************************************************************************
* Copyright (c) 2016 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is 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.jboss.tools.openshift.internal.common.ui.utils;

import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;

public abstract class DialogAdvancedPart {
protected Button advancedButton;
protected DialogChildVisibilityAdapter advancedSectionVisibilityAdapter;

public DialogAdvancedPart() {
}

public final void createAdvancedGroup(Composite parent, int numColumns) {
// advanced button
this.advancedButton = new Button(parent, SWT.NONE);
advancedButton.setText(getAdvancedButtonLabel(false));
GridDataFactory.fillDefaults()
.align(SWT.BEGINNING, SWT.CENTER).span(numColumns, 1).applyTo(advancedButton);

// advanced composite
Composite advancedComposite = new Composite(parent, SWT.NONE);
GridData advancedCompositeGridData = GridDataFactory.fillDefaults()
.align(SWT.FILL, SWT.FILL).grab(true, false).span(numColumns, 1).create();
advancedComposite.setLayoutData(advancedCompositeGridData);
adjustAdvancedCompositeLayout(GridLayoutFactory.fillDefaults()).applyTo(advancedComposite);

this.advancedSectionVisibilityAdapter = new DialogChildVisibilityAdapter(advancedComposite, false);
advancedButton.addSelectionListener(onAdvancedClicked());

createAdvancedContent(advancedComposite);
}

protected GridLayoutFactory adjustAdvancedCompositeLayout(GridLayoutFactory gridLayoutFactory) {
return gridLayoutFactory;
}

private SelectionListener onAdvancedClicked() {
return new SelectionAdapter() {

@Override
public void widgetSelected(SelectionEvent e) {
showAdvancedSection(!advancedSectionVisibilityAdapter.isVisible());
}
};
}

public void showAdvancedSection(boolean visible) {
advancedSectionVisibilityAdapter.setVisible(visible);
advancedButton.setText(getAdvancedButtonLabel(visible));
}

protected String getAdvancedButtonLabel(boolean visible) {
if (visible) {
return " << Advanced ";
} else {
return " Advanced >> ";
}
}

protected abstract void createAdvancedContent(Composite advancedComposite);
}
Expand Up @@ -8,7 +8,7 @@
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.openshift.express.internal.ui.utils;
package org.jboss.tools.openshift.internal.common.ui.utils;

import org.eclipse.core.runtime.Assert;
import org.eclipse.swt.SWT;
Expand Down
Expand Up @@ -50,7 +50,6 @@
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
Expand All @@ -72,7 +71,6 @@
import org.jboss.tools.openshift.express.internal.core.util.CartridgeToStringConverter;
import org.jboss.tools.openshift.express.internal.core.util.ExpressResourceLabelUtils;
import org.jboss.tools.openshift.express.internal.ui.ExpressUIActivator;
import org.jboss.tools.openshift.express.internal.ui.utils.DialogChildVisibilityAdapter;
import org.jboss.tools.openshift.express.internal.ui.utils.Logger;
import org.jboss.tools.openshift.express.internal.ui.viewer.EmbeddableCartridgeViewerSorter;
import org.jboss.tools.openshift.express.internal.ui.viewer.EqualityComparer;
Expand All @@ -86,6 +84,7 @@
import org.jboss.tools.openshift.internal.common.ui.databinding.MultiConverter;
import org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater;
import org.jboss.tools.openshift.internal.common.ui.databinding.TrimmingStringConverter;
import org.jboss.tools.openshift.internal.common.ui.utils.DialogAdvancedPart;
import org.jboss.tools.openshift.internal.common.ui.utils.StyledTextUtils;
import org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder;
import org.jboss.tools.openshift.internal.common.ui.utils.UIUtils;
Expand Down Expand Up @@ -115,8 +114,8 @@ public class ApplicationConfigurationWizardPage extends AbstractOpenShiftWizardP
private ApplicationConfigurationWizardPageModel pageModel;
private Text applicationNameText;
private OpenShiftApplicationWizardModel wizardModel;
private Button advancedButton;
private DialogChildVisibilityAdapter advancedSectionVisibilityAdapter;

private DialogAdvancedPart advancedPart;

ApplicationConfigurationWizardPage(IWizard wizard, OpenShiftApplicationWizardModel wizardModel) {
super("New or existing OpenShift Application", "", "New or existing OpenShift Application, wizard", wizard);
Expand Down Expand Up @@ -366,9 +365,9 @@ public void handleValueChange(ValueChangeEvent event) {
cartridgesGroup.setText(getCartridgesListLabel(template));
if (template instanceof IQuickstartApplicationTemplate) {
IQuickstartApplicationTemplate quickstart = (IQuickstartApplicationTemplate) template;
showAdvancedSection(!StringUtils.isEmpty(quickstart.getInitialGitUrl()));
advancedPart.showAdvancedSection(!StringUtils.isEmpty(quickstart.getInitialGitUrl()));
} else {
showAdvancedSection(false);
advancedPart.showAdvancedSection(false);
}
}
}
Expand Down Expand Up @@ -480,18 +479,19 @@ private Composite getEmbeddableCartridgesButtons(
}

private void createAdvancedGroup(Composite parent, DataBindingContext dbc) {
// advanced button
this.advancedButton = new Button(parent, SWT.NONE);
advancedButton.setText(getAdvancedButtonLabel(false));
GridDataFactory.fillDefaults()
.align(SWT.BEGINNING, SWT.CENTER).span(3, 1).applyTo(advancedButton);

// advanced composite
Composite advancedComposite = new Composite(parent, SWT.NONE);
GridData advancedCompositeGridData = GridDataFactory.fillDefaults()
.align(SWT.FILL, SWT.FILL).grab(true, false).span(3, 1).create();
advancedComposite.setLayoutData(advancedCompositeGridData);
GridLayoutFactory.fillDefaults().applyTo(advancedComposite);
// advanced part
advancedPart = new DialogAdvancedPart() {

@Override
protected void createAdvancedContent(Composite advancedComposite) {
doCreateAdvancedContent(advancedComposite, dbc);
}
};

advancedPart.createAdvancedGroup(parent, 3);
}

private void doCreateAdvancedContent(Composite advancedComposite, DataBindingContext dbc) {

// source group
Group sourceGroup = new Group(advancedComposite, SWT.NONE);
Expand Down Expand Up @@ -560,10 +560,6 @@ private void createAdvancedGroup(Composite parent, DataBindingContext dbc) {
ControlDecorationSupport.create(
sourceCodeUrlValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());

this.advancedSectionVisibilityAdapter = new DialogChildVisibilityAdapter(advancedComposite, false);
advancedButton.addSelectionListener(
onAdvancedClicked());

// explanation
StyledText sourceCodeExplanationText = new StyledText(sourceGroup, SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY);
sourceCodeExplanationText.setAlwaysShowScrollBars(false);
Expand Down Expand Up @@ -748,29 +744,6 @@ protected void replaceSelectedCartridge(ICartridge selectedCartridge, ICartridge
};
}

private SelectionListener onAdvancedClicked() {
return new SelectionAdapter() {

@Override
public void widgetSelected(SelectionEvent e) {
showAdvancedSection(!advancedSectionVisibilityAdapter.isVisible());
}
};
}

protected void showAdvancedSection(boolean visible) {
advancedSectionVisibilityAdapter.setVisible(visible);
advancedButton.setText(getAdvancedButtonLabel(visible));
}

protected String getAdvancedButtonLabel(boolean visible) {
if (visible) {
return " << Advanced ";
} else {
return " Advanced >> ";
}
}

private SelectionListener onBrowseEnvironmentVariables(final DataBindingContext dbc) {
return new SelectionAdapter() {

Expand Down

0 comments on commit 7a2589b

Please sign in to comment.