statistical-algorithms-impo.../src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/client/tools/input/ProjectInfoPanel.java

142 lines
4.5 KiB
Java

package org.gcube.portlets.user.statisticalalgorithmsimporter.client.tools.input;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.ProjectInfo;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.event.shared.EventBus;
import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode;
import com.sencha.gxt.core.client.util.Margins;
import com.sencha.gxt.widget.core.client.ContentPanel;
import com.sencha.gxt.widget.core.client.container.MarginData;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
import com.sencha.gxt.widget.core.client.form.FieldLabel;
import com.sencha.gxt.widget.core.client.form.TextField;
/**
*
* @author giancarlo email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class ProjectInfoPanel extends ContentPanel {
@SuppressWarnings("unused")
private EventBus eventBus;
private TextField projectName;
private TextField projectDescription;
private TextField projectClassName;
public ProjectInfoPanel(Project project, EventBus eventBus) {
super();
Log.debug("ProjectInfoPanel");
this.eventBus = eventBus;
// msgs = GWT.create(ServiceCategoryMessages.class);
try {
init();
create(project);
} catch (Throwable e) {
e.printStackTrace();
}
}
private void init() {
setHeaderVisible(false);
setResize(true);
setBodyBorder(false);
setBorders(false);
forceLayoutOnResize = true;
}
private void create(Project project) {
projectName = new TextField();
projectName.setAllowBlank(false);
projectName.setEmptyText("Enter name...");
FieldLabel projectNameLabel = new FieldLabel(projectName, "Name");
projectDescription = new TextField();
projectDescription.setAllowBlank(false);
projectDescription.setEmptyText("Enter description...");
FieldLabel projectDescriptionLabel = new FieldLabel(projectDescription,
"Description");
projectClassName = new TextField();
projectClassName.setAllowBlank(false);
projectClassName.setEmptyText("Enter class name...");
FieldLabel projectClassNameLabel = new FieldLabel(projectClassName,
"Class Name");
if (project != null && project.getInputData()!=null && project.getInputData().getProjectInfo() != null) {
if (project.getInputData().getProjectInfo().getName() != null) {
projectName.setValue(project.getInputData().getProjectInfo().getName());
}
if (project.getInputData().getProjectInfo().getDescription() != null) {
projectDescription.setValue(project.getInputData().getProjectInfo()
.getDescription());
}
if (project.getInputData().getProjectInfo().getClassName() != null) {
projectClassName.setValue(project.getInputData().getProjectInfo()
.getClassName());
}
}
VerticalLayoutContainer vlc = new VerticalLayoutContainer();
vlc.setAdjustForScroll(false);
vlc.setScrollMode(ScrollMode.NONE);
vlc.add(projectNameLabel, new VerticalLayoutData(1, -1, new Margins(5,
0, 5, 0)));
vlc.add(projectDescriptionLabel, new VerticalLayoutData(1, -1,
new Margins(5, 0, 5, 0)));
vlc.add(projectClassNameLabel, new VerticalLayoutData(1, -1,
new Margins(5, 0, 5, 0)));
add(vlc, new MarginData(new Margins(0)));
}
public void update(Project project) {
Log.debug("Update Project Info: " + project);
if (project != null && project.getInputData()!=null && project.getInputData().getProjectInfo() != null) {
if (project.getInputData().getProjectInfo().getName() != null) {
projectName.setValue(project.getInputData().getProjectInfo().getName());
} else {
projectName.clear();
}
if (project.getInputData().getProjectInfo().getDescription() != null) {
projectDescription.setValue(project.getInputData().getProjectInfo()
.getDescription());
} else {
projectDescription.clear();
}
if (project.getInputData().getProjectInfo().getClassName() != null) {
projectClassName.setValue(project.getInputData().getProjectInfo()
.getClassName());
} else {
projectClassName.clear();
}
} else {
projectName.clear();
projectDescription.clear();
projectClassName.clear();
}
}
public ProjectInfo getProjectInfo() {
String name = projectName.getCurrentValue();
String description = projectDescription.getCurrentValue();
String className = projectClassName.getCurrentValue();
return new ProjectInfo(name, description, className);
}
}