2015-11-27 19:03:06 +01:00
|
|
|
package org.gcube.portlets.user.statisticalalgorithmsimporter.client.maindata;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.SessionExpiredEvent;
|
|
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.rpc.StatAlgoImporterServiceAsync;
|
|
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.type.SessionExpiredType;
|
|
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.utils.UtilsGXT3;
|
|
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.code.CodeData;
|
|
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterSessionExpiredException;
|
|
|
|
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
|
|
import com.google.gwt.event.shared.EventBus;
|
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
|
import com.sencha.gxt.widget.core.client.ContentPanel;
|
|
|
|
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
|
|
|
|
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
|
|
|
|
|
|
|
|
import edu.ycp.cs.dh.acegwt.client.ace.AceEditor;
|
|
|
|
import edu.ycp.cs.dh.acegwt.client.ace.AceEditorMode;
|
|
|
|
import edu.ycp.cs.dh.acegwt.client.ace.AceEditorTheme;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author giancarlo email: <a
|
|
|
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class CodeEditPanel extends ContentPanel {
|
|
|
|
|
|
|
|
private EventBus eventBus;
|
|
|
|
private AceEditor editor;
|
|
|
|
|
|
|
|
public CodeEditPanel(EventBus eventBus) {
|
|
|
|
super();
|
|
|
|
Log.debug("CodeEditPanel");
|
|
|
|
this.eventBus = eventBus;
|
|
|
|
|
|
|
|
// msgs = GWT.create(ServiceCategoryMessages.class);
|
|
|
|
init();
|
|
|
|
create();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void init() {
|
|
|
|
forceLayoutOnResize = true;
|
|
|
|
setBodyBorder(false);
|
|
|
|
setBorders(false);
|
|
|
|
setHeaderVisible(false);
|
|
|
|
setResize(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void create() {
|
|
|
|
editor = new AceEditor();
|
|
|
|
VerticalLayoutContainer v = new VerticalLayoutContainer();
|
|
|
|
v.add(editor, new VerticalLayoutData(1, 1));
|
|
|
|
|
|
|
|
add(v);
|
|
|
|
editor.startEditor();
|
|
|
|
loadCode();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void loadCode() {
|
|
|
|
StatAlgoImporterServiceAsync.INSTANCE
|
|
|
|
.getCode(new AsyncCallback<ArrayList<CodeData>>() {
|
|
|
|
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
if (caught instanceof StatAlgoImporterSessionExpiredException) {
|
|
|
|
eventBus.fireEvent(new SessionExpiredEvent(
|
|
|
|
SessionExpiredType.EXPIREDONSERVER));
|
|
|
|
} else {
|
|
|
|
Log.error("Error retrieving code: "
|
|
|
|
+ caught.getLocalizedMessage());
|
|
|
|
UtilsGXT3.alert("Error",
|
|
|
|
caught.getLocalizedMessage());
|
|
|
|
}
|
|
|
|
caught.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onSuccess(ArrayList<CodeData> result) {
|
|
|
|
Log.debug("loaded " + result.size() + " code lines");
|
|
|
|
String text = new String();
|
|
|
|
for (CodeData codeData : result) {
|
2015-12-01 18:35:46 +01:00
|
|
|
//Log.debug("Read: " + codeData);
|
2015-11-27 19:03:06 +01:00
|
|
|
text+=codeData.getCodeLine()+"\r\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
editor.setShowPrintMargin(false);
|
|
|
|
editor.setMode(AceEditorMode.R);
|
|
|
|
editor.setTheme(AceEditorTheme.ECLIPSE);
|
|
|
|
editor.setText(text);
|
|
|
|
forceLayout();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void codeUpdate() {
|
|
|
|
loadCode();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|