2013-02-06 23:25:43 +01:00
|
|
|
package org.gcube.portlets.user.reportgenerator.client.targets;
|
|
|
|
|
2013-02-08 17:02:37 +01:00
|
|
|
import org.gcube.portlets.d4sreporting.common.shared.ComponentType;
|
2013-02-06 23:25:43 +01:00
|
|
|
import org.gcube.portlets.user.reportgenerator.client.ReportGenerator;
|
|
|
|
import org.gcube.portlets.user.reportgenerator.client.Presenter.Presenter;
|
|
|
|
|
2013-03-12 18:10:16 +01:00
|
|
|
import com.google.gwt.dom.client.Style.Unit;
|
2013-02-06 23:25:43 +01:00
|
|
|
import com.google.gwt.event.dom.client.KeyUpEvent;
|
|
|
|
import com.google.gwt.event.dom.client.KeyUpHandler;
|
2013-03-12 18:10:16 +01:00
|
|
|
import com.google.gwt.event.dom.client.MouseDownEvent;
|
|
|
|
import com.google.gwt.event.dom.client.MouseDownHandler;
|
2013-02-06 23:25:43 +01:00
|
|
|
import com.google.gwt.event.dom.client.MouseOutEvent;
|
|
|
|
import com.google.gwt.event.dom.client.MouseOutHandler;
|
|
|
|
import com.google.gwt.user.client.ui.HTML;
|
|
|
|
import com.google.gwt.user.client.ui.HasVerticalAlignment;
|
2013-03-12 18:10:16 +01:00
|
|
|
import com.google.gwt.user.client.ui.RichTextArea;
|
2013-02-06 23:25:43 +01:00
|
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
|
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
/**
|
|
|
|
* <code> BasicTextArea </code>
|
|
|
|
*
|
|
|
|
* @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it
|
|
|
|
* @version July 2011 (3.0)
|
|
|
|
*/
|
|
|
|
public class BasicTextArea extends ReportTextArea {
|
2013-03-12 18:10:16 +01:00
|
|
|
private RichTextArea textArea = new RichTextArea();
|
2013-03-13 11:06:47 +01:00
|
|
|
//private TextArea textArea = new TextArea();
|
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
private VerticalPanel myPanel;
|
|
|
|
|
|
|
|
int currHeight = 0;
|
2013-03-13 11:06:47 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
|
2013-03-12 18:10:16 +01:00
|
|
|
|
|
|
|
public BasicTextArea(ComponentType type, final Presenter presenter, int left, int top, final int width, final int height, boolean hasComments, boolean showClose) {
|
|
|
|
super(type, presenter, left, top, width, height, hasComments, showClose);
|
|
|
|
currHeight = height;
|
2013-02-06 23:25:43 +01:00
|
|
|
myPanel = getResizablePanel();
|
|
|
|
|
|
|
|
textArea.setPixelSize(width, height);
|
2013-03-12 18:10:16 +01:00
|
|
|
textArea.getElement().getStyle().setMarginTop(-4, Unit.PX); //this is needed because the richtextarea has margin 8px and a not able to modify it via css
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
textArea.addMouseOutHandler(new MouseOutHandler() {
|
|
|
|
|
|
|
|
public void onMouseOut(MouseOutEvent event) {
|
|
|
|
presenter.storeChangeInSession((Widget) event.getSource());
|
|
|
|
}
|
|
|
|
});
|
2013-02-13 18:26:22 +01:00
|
|
|
textArea.setStyleName("report-ui-component");
|
2013-03-13 11:06:47 +01:00
|
|
|
|
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
switch (type) {
|
2013-03-13 11:06:47 +01:00
|
|
|
|
2013-03-04 19:15:59 +01:00
|
|
|
case BODY_NOT_FORMATTED:
|
|
|
|
textArea.addStyleName("simpleText");
|
|
|
|
myPanel.setTitle("Simple text");
|
|
|
|
break;
|
2013-02-06 23:25:43 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
myPanel.add(textArea);
|
|
|
|
myPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);
|
|
|
|
myPanel.setPixelSize(width, height);
|
|
|
|
|
|
|
|
textArea.addMouseOutHandler(new MouseOutHandler() {
|
|
|
|
|
|
|
|
public void onMouseOut(MouseOutEvent event) {
|
|
|
|
presenter.storeChangeInSession((Widget) event.getSource());
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
2013-03-12 18:10:16 +01:00
|
|
|
|
|
|
|
textArea.addKeyUpHandler(new KeyUpHandler() {
|
|
|
|
public void onKeyUp(KeyUpEvent event) {
|
|
|
|
HTML div = ReportGenerator.get().getDivHidden();
|
2013-03-13 11:06:47 +01:00
|
|
|
div.setHTML(textArea.getHTML());
|
2013-03-12 18:10:16 +01:00
|
|
|
int newHeight = div.getOffsetHeight();
|
2013-03-13 11:06:47 +01:00
|
|
|
|
|
|
|
resizePanel(width, newHeight);
|
|
|
|
presenter.resizeTemplateComponentInModel(myInstance, width, newHeight);
|
|
|
|
currHeight = newHeight;
|
|
|
|
|
2013-03-12 18:10:16 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
textArea.addMouseDownHandler(new MouseDownHandler() {
|
|
|
|
public void onMouseDown(MouseDownEvent event) {
|
|
|
|
HTML div = ReportGenerator.get().getDivHidden();
|
2013-03-13 11:06:47 +01:00
|
|
|
div.setHTML(textArea.getHTML());
|
2013-03-12 18:10:16 +01:00
|
|
|
int newHeight = div.getOffsetHeight();
|
2013-03-13 11:06:47 +01:00
|
|
|
|
|
|
|
resizePanel(width, newHeight);
|
|
|
|
presenter.resizeTemplateComponentInModel(myInstance, width, newHeight);
|
|
|
|
currHeight = newHeight;
|
|
|
|
|
2013-03-12 18:10:16 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
public String getText() {
|
|
|
|
return textArea.getText();
|
|
|
|
}
|
2013-03-13 11:06:47 +01:00
|
|
|
|
2013-02-06 23:25:43 +01:00
|
|
|
public void setText(String text) {
|
|
|
|
textArea.setText(text);
|
2013-03-13 11:06:47 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public RichTextArea getRichTextArea() {
|
|
|
|
return null;
|
2013-02-06 23:25:43 +01:00
|
|
|
}
|
|
|
|
|
2013-03-12 18:10:16 +01:00
|
|
|
/**
|
|
|
|
* used to resize the panel
|
|
|
|
* @param width w
|
|
|
|
* @param height h
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void resizePanel(int width, int height) {
|
|
|
|
if (height > 25) {
|
|
|
|
mainPanel.setPixelSize(width, height);
|
|
|
|
resizablePanel.setPixelSize(width, height);
|
|
|
|
textArea.setPixelSize(width-4, height);
|
|
|
|
currHeight = height;
|
|
|
|
}
|
|
|
|
}
|
2013-02-06 23:25:43 +01:00
|
|
|
|
|
|
|
}
|