mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-13 14:12:11 +00:00
Bug 4211: added InlineEditLabel
This commit is contained in:
1 parent
ad05f32c1c
commit
d119c731eb
2 files changed
+89
No files matched your search
+67
@@ -0,0 +1,67 @@
|
||||
package com.sap.sailing.gwt.home.shared.partials.editable;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
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.Button;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.HasText;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
import com.google.gwt.user.client.ui.TextBox;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
public class InlineEditLabel extends Composite implements HasText {
|
||||
|
||||
private static InlineEditTextfieldUiBinder uiBinder = GWT.create(InlineEditTextfieldUiBinder.class);
|
||||
|
||||
interface InlineEditTextfieldUiBinder extends UiBinder<Widget, InlineEditLabel> {
|
||||
}
|
||||
|
||||
@UiField
|
||||
Button button;
|
||||
|
||||
@UiField
|
||||
TextBox textBox;
|
||||
|
||||
@UiField
|
||||
Label label;
|
||||
|
||||
private boolean state = false;
|
||||
|
||||
public InlineEditLabel() {
|
||||
initWidget(uiBinder.createAndBindUi(this));
|
||||
updateState(false);
|
||||
}
|
||||
|
||||
@UiHandler("button")
|
||||
void onClick(ClickEvent e) {
|
||||
updateState(!state);
|
||||
}
|
||||
|
||||
private void updateState(boolean newState) {
|
||||
if (newState) {
|
||||
textBox.setWidth((label.getOffsetWidth() + 7) + "px");
|
||||
label.setVisible(false);
|
||||
textBox.setVisible(true);
|
||||
textBox.setText(label.getText());
|
||||
} else {
|
||||
label.setVisible(true);
|
||||
textBox.setVisible(false);
|
||||
label.setText(textBox.getText());
|
||||
|
||||
}
|
||||
this.state = newState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setText(String text) {
|
||||
label.setText(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return label.getText();
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
<!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">
|
||||
<ui:style>
|
||||
.button {
|
||||
font-weight: bold;
|
||||
}
|
||||
.label{
|
||||
margin-left: 2px;
|
||||
margin-right: 4px;
|
||||
margin-top: 4px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
.inline{
|
||||
display:inline-block
|
||||
}
|
||||
</ui:style>
|
||||
<g:HTMLPanel>
|
||||
<g:TextBox ui:field="textBox" styleName="{style.inline}" />
|
||||
<g:Label ui:field="label" styleName="{style.label} {style.inline}" />
|
||||
<g:Button styleName="{style.button} {style.inline}" ui:field="button" text="Edit" />
|
||||
</g:HTMLPanel>
|
||||
</ui:UiBinder>
|
||||
Reference in new issue
Block a user