Skip to content

Commit

Permalink
CHE-1002 Add target UX improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Vitaliy Guliy <vguliy@codenvy.com>
  • Loading branch information
Vitaliy Guliy committed Apr 25, 2016
1 parent 34b9a99 commit 1a6f40b
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 39 deletions.
Expand Up @@ -340,35 +340,75 @@ private void updateButtons() {
return;
}

// Update text of Connect / Disconnect button
if (selectedTarget.isConnected()) {
view.setConnectButtonText("Disconnect");
} else {
view.setConnectButtonText("Connect");
}
view.enableConnectButton(!selectedTarget.isDirty());

view.enableCancelButton(selectedTarget.isDirty());
// Disable Save and Cancel buttons and enable Connect for non dirty target.
if (!selectedTarget.isDirty()) {
view.enableConnectButton(true);
view.enableCancelButton(false);
view.enableSaveButton(false);

view.unmarkTargetName();
view.unmarkHost();
view.unmarkPort();
return;
}

view.enableConnectButton(false);
view.enableCancelButton(true);

if (StringUtils.isNullOrEmpty(view.getTargetName()) ||
StringUtils.isNullOrEmpty(view.getHost()) ||
StringUtils.isNullOrEmpty(view.getPort())) {
// target name must be not empty
if (view.getTargetName().isEmpty()) {
view.markTargetNameInvalid();
view.enableSaveButton(false);
} else {
if (selectedTarget.isDirty()) {
for (Target target : targets) {
if (target == selectedTarget) {
continue;
}
return;
}

if (target.getName().equals(view.getTargetName())) {
view.enableSaveButton(false);
return;
}
boolean enableSave = true;

// check target name to being not empty
if (view.getTargetName().isEmpty()) {
enableSave = false;
view.markTargetNameInvalid();
} else {
boolean targetAlreadyExists = false;
for (Target target : targets) {
if (target != selectedTarget && target.getName().equals(view.getTargetName())) {
targetAlreadyExists = true;
break;
}
}

view.enableSaveButton(selectedTarget.isDirty());
if (targetAlreadyExists) {
enableSave = false;
view.markTargetNameInvalid();
} else {
view.unmarkTargetName();
}
}

// check host to being not empty
if (view.getHost().isEmpty()) {
enableSave = false;
view.markHostInvalid();
} else {
view.unmarkHost();
}

// check port to being not empty
if (view.getPort().isEmpty()) {
enableSave = false;
view.markPortInvalid();
} else {
view.unmarkPort();
}

view.enableSaveButton(enableSave);
}

@Override
Expand Down Expand Up @@ -700,24 +740,32 @@ protected void onErrorReceived(Throwable exception) {
* Ensures machine is started.
*/
private void onConnected(final String machineId) {
machineService.getMachine(machineId).then(new Operation<MachineDto>() {
// There is a little bug in machine service on the server side.
// The machine info is updated with a little delay after running a machine.
// Using timer must fix the problem.
new Timer() {
@Override
public void apply(MachineDto machineDto) throws OperationException {
if (machineDto.getStatus() == RUNNING) {
eventBus.fireEvent(new MachineStateEvent(machineDto, MachineStateEvent.MachineAction.RUNNING));
connectNotification.setTitle(machineLocale.targetsViewConnectSuccess(machineDto.getConfig().getName()));
connectNotification.setStatus(StatusNotification.Status.SUCCESS);
updateTargets(machineDto.getConfig().getName());
} else {
onConnectingFailed(null);
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
onConnectingFailed(null);
public void run() {
machineService.getMachine(machineId).then(new Operation<MachineDto>() {
@Override
public void apply(MachineDto machineDto) throws OperationException {
if (machineDto.getStatus() == RUNNING) {
eventBus.fireEvent(new MachineStateEvent(machineDto, MachineStateEvent.MachineAction.RUNNING));
connectNotification.setTitle(machineLocale.targetsViewConnectSuccess(machineDto.getConfig().getName()));
connectNotification.setStatus(StatusNotification.Status.SUCCESS);
updateTargets(machineDto.getConfig().getName());
} else {
onConnectingFailed(null);
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
onConnectingFailed(null);
}
});
}
});
}.schedule(500);
}

/**
Expand Down
Expand Up @@ -107,6 +107,36 @@ public interface TargetsView extends View<TargetsView.ActionDelegate> {
*/
String getPort();

/**
* Adds error mark to target name field.
*/
void markTargetNameInvalid();

/**
* Removes error mark from target name field.
*/
void unmarkTargetName();

/**
* Adds error mark to host field.
*/
void markHostInvalid();

/**
* Removes error mark from host field.
*/
void unmarkHost();

/**
* Adds error mark to port field.
*/
void markPortInvalid();

/**
* Removes error mark from port field.
*/
void unmarkPort();

/**
* Sets SSH user name.
*
Expand Down
Expand Up @@ -98,13 +98,13 @@ interface TargetsViewImplUiBinder extends UiBinder<Widget, TargetsViewImpl> {
FlowPanel propertiesPanel;

@UiField
TextBox targetName;
org.eclipse.che.ide.ui.TextBox targetName;

@UiField
TextBox host;
org.eclipse.che.ide.ui.TextBox host;

@UiField
TextBox port;
org.eclipse.che.ide.ui.TextBox port;

@UiField
TextBox userName;
Expand Down Expand Up @@ -428,6 +428,36 @@ public String getTargetName() {
return targetName.getValue();
}

@Override
public void markTargetNameInvalid() {
targetName.markInvalid();
}

@Override
public void unmarkTargetName() {
targetName.unmark();
}

@Override
public void markHostInvalid() {
host.markInvalid();
}

@Override
public void unmarkHost() {
host.unmark();
}

@Override
public void markPortInvalid() {
port.markInvalid();
}

@Override
public void unmarkPort() {
port.unmark();
}

@Override
public void setHost(String host) {
this.host.setValue(host);
Expand Down
Expand Up @@ -13,7 +13,7 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'
xmlns:che='urn:import:org.eclipse.che.ide.ui.listbox'>
xmlns:ide='urn:import:org.eclipse.che.ide.ui'>

<ui:with field='machineLocale' type='org.eclipse.che.ide.extension.machine.client.MachineLocalizationConstant'/>

Expand Down Expand Up @@ -165,13 +165,13 @@
<g:FlowPanel ui:field="propertiesPanel" styleName="{style.propertiesPanel}" visible="false">

<g:Label width="100%" text="Name" addStyleNames="{style.label} {style.delimiter}"/>
<g:TextBox width="100%" height="14px" ui:field="targetName" tabIndex="0"/>
<ide:TextBox width="100%" height="14px" ui:field="targetName" tabIndex="0"/>

<g:Label width="100%" text="Host" addStyleNames="{style.label} {style.delimiter}"/>
<g:TextBox width="100%" height="14px" ui:field="host" tabIndex="0"/>
<ide:TextBox width="100%" height="14px" ui:field="host" tabIndex="0"/>

<g:Label width="100%" text="Port" addStyleNames="{style.label}"/>
<g:TextBox width="100%" height="14px" ui:field="port" tabIndex="0"/>
<ide:TextBox width="100%" height="14px" ui:field="port" tabIndex="0"/>

<g:Label width="100%" text="Login" addStyleNames="{style.label} {style.delimiter}"/>
<g:TextBox width="100%" height="14px" ui:field="userName" tabIndex="0"/>
Expand Down

0 comments on commit 1a6f40b

Please sign in to comment.