Project

General

Profile

« Previous | Next » 

Revision 49522

Copying to move to dnet45

View differences:

modules/uoa-gwt-widgets/trunk/deploy.info
1
{
2
  "type_source": "SVN", 
3
  "goal": "package -U -T 4C source:jar", 
4
  "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-gwt-widgets/trunk", 
5
  "deploy_repository": "dnet4-snapshots", 
6
  "version": "4", 
7
  "mail": "antleb@di.uoa.gr, stefania.martziou@imis.athena-innovation.gr, nikonas@di.uoa.gr", 
8
  "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet4-snapshots", 
9
  "name": "uoa-gwt-widgets"
10
}
modules/uoa-gwt-widgets/trunk/src/main/java/eu/dnetlib/gwt/server/service/SpringGwtRemoteServiceServlet.java
1
package eu.dnetlib.gwt.server.service;
2

  
3
import javax.servlet.http.HttpServletRequest;
4

  
5
import org.apache.log4j.Logger;
6
import org.springframework.web.context.WebApplicationContext;
7
import org.springframework.web.context.support.WebApplicationContextUtils;
8

  
9
import com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException;
10
import com.google.gwt.user.client.rpc.RemoteService;
11
import com.google.gwt.user.client.rpc.SerializationException;
12
import com.google.gwt.user.server.rpc.RPC;
13
import com.google.gwt.user.server.rpc.RPCRequest;
14
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
15

  
16
@SuppressWarnings("serial")
17
public class SpringGwtRemoteServiceServlet extends RemoteServiceServlet {
18

  
19
	private static final Logger LOG = Logger.getLogger(SpringGwtRemoteServiceServlet.class);
20

  
21
	@Override
22
	public void init() {
23
		if (LOG.isDebugEnabled()) {
24
			LOG.debug("Spring GWT service exporter deployed");
25
		}
26
	}
27

  
28
	@Override
29
	public String processCall(String payload) throws SerializationException {
30
		try {
31
			Object handler = getBean(getThreadLocalRequest());
32
			RPCRequest rpcRequest = RPC.decodeRequest(payload, handler.getClass(), this);
33
			onAfterRequestDeserialized(rpcRequest);
34
			if (LOG.isDebugEnabled()) {
35
				LOG.debug("Invoking " + handler.getClass().getName() + "." + rpcRequest.getMethod().getName());
36
			}
37
			return RPC.invokeAndEncodeResponse(handler, rpcRequest.getMethod(), rpcRequest.getParameters(), rpcRequest
38
					.getSerializationPolicy());
39
		} catch (IncompatibleRemoteServiceException ex) {
40
			log("An IncompatibleRemoteServiceException was thrown while processing this call.", ex);
41
			return RPC.encodeResponseForFailure(null, ex);
42
		}
43
	}
44

  
45
	/**
46
	 * Determine Spring bean to handle request based on request URL, e.g. a
47
	 * request ending in /myService will be handled by bean with name
48
	 * "myService".
49
	 * 
50
	 * @param request
51
	 * @return handler bean
52
	 */
53
	protected Object getBean(HttpServletRequest request) {
54
		String service = getService(request);
55
		Object bean = getBean(service);
56
		if (!(bean instanceof RemoteService)) {
57
			throw new IllegalArgumentException("Spring bean is not a GWT RemoteService: " + service + " (" + bean + ")");
58
		}
59
		if (LOG.isDebugEnabled()) {
60
			LOG.debug("Bean for service " + service + " is " + bean);
61
		}
62
		return bean;
63
	}
64

  
65
	/**
66
	 * Parse the service name from the request URL.
67
	 * 
68
	 * @param request
69
	 * @return bean name
70
	 */
71
	protected String getService(HttpServletRequest request) {
72
		String url = request.getRequestURI();
73
		String service = url.substring(url.lastIndexOf("/") + 1);
74
		if (LOG.isDebugEnabled()) {
75
			LOG.debug("Service for URL " + url + " is " + service);
76
		}
77
		return service;
78
	}
79

  
80
	/**
81
	 * Look up a spring bean with the specified name in the current web
82
	 * application context.
83
	 * 
84
	 * @param name
85
	 *            bean name
86
	 * @return the bean
87
	 */
88
	protected Object getBean(String name) {
89
		WebApplicationContext applicationContext = WebApplicationContextUtils
90
				.getWebApplicationContext(getServletContext());
91
		if (applicationContext == null) {
92
			throw new IllegalStateException("No Spring web application context found");
93
		}
94
		if (!applicationContext.containsBean(name)) {
95
			{
96
				throw new IllegalArgumentException("Spring bean not found: " + name);
97
			}
98
		}
99
		return applicationContext.getBean(name);
100
	}
101
}
modules/uoa-gwt-widgets/trunk/src/main/java/eu/dnetlib/gwt/server/help/HelpServiceImpl.java
1
package eu.dnetlib.gwt.server.help;
2

  
3
import eu.dnetlib.gwt.client.help.HelpService;
4
import eu.dnetlib.gwt.server.service.SpringGwtRemoteServiceServlet;
5
import eu.dnetlib.gwt.shared.Help;
6
import org.springframework.beans.factory.annotation.Autowired;
7
import org.springframework.dao.EmptyResultDataAccessException;
8
import org.springframework.stereotype.Service;
9
import org.springframework.transaction.annotation.Transactional;
10

  
11
import java.util.List;
12

  
13
/**
14
 * Created by stefania on 3/9/16.
15
 */
16
@Service("helpService")
17
@Transactional
18
public class HelpServiceImpl extends SpringGwtRemoteServiceServlet implements HelpService {
19

  
20
    @Autowired
21
    private HelpDAO helpDAO;
22

  
23
    @Override
24
    public Help saveHelp(Help help) {
25
        return helpDAO.saveHelp(help);
26
    }
27

  
28
    @Override
29
    public Help getHelpById(String id) {
30
        try {
31
            return helpDAO.getById(id);
32
        } catch (EmptyResultDataAccessException e) {
33
            return null;
34
        }
35
    }
36

  
37
    @Override
38
    public List<Help> getAll() {
39
        return helpDAO.getAll();
40
    }
41

  
42
    @Override
43
    public void delete(String helpId) {
44
        helpDAO.delete(helpId);
45
    }
46
}
modules/uoa-gwt-widgets/trunk/src/main/java/eu/dnetlib/gwt/server/help/HelpDAO.java
1
package eu.dnetlib.gwt.server.help;
2

  
3
import eu.dnetlib.gwt.shared.Help;
4
import org.springframework.beans.factory.annotation.Autowired;
5
import org.springframework.beans.factory.annotation.Qualifier;
6
import org.springframework.jdbc.core.JdbcTemplate;
7
import org.springframework.jdbc.core.RowMapper;
8
import org.springframework.stereotype.Component;
9

  
10
import javax.sql.DataSource;
11
import java.sql.ResultSet;
12
import java.sql.SQLException;
13
import java.sql.Types;
14
import java.util.List;
15

  
16
/**
17
 * Created by antleb on 4/17/15.
18
 */
19
@Component(value = "helpDAO")
20
public class HelpDAO {
21

  
22
	@Autowired
23
	@Qualifier("repomanager.dataSource")
24
	private DataSource dataSource;
25

  
26
	private final static String UPDATE_HELP = "update help set name=?, text=? where id=?";
27
	private final static String INSERT_HELP = "insert into help (name, text, id) values (?, ?, ?)";
28
	private final static String GET_BY_ID = "select id, name, text from help where id = ?";
29
	private final static String GET_ALL = "select id, name, text from help";
30
	private final static String DELETE = "delete from help where id = ?";
31

  
32

  
33
	private RowMapper<Help> helpRowMapper = new RowMapper<Help>() {
34
		@Override
35
		public Help mapRow(ResultSet rs, int i) throws SQLException {
36
			return new Help(rs.getString("id"), rs.getString("name"), rs.getString("text"));
37
		}
38
	};
39

  
40
	public Help saveHelp(Help help) {
41
		JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
42

  
43
		if (jdbcTemplate.update(UPDATE_HELP, new String[]{help.getName(), help.getText(), help.getId()}, new int[]{Types.VARCHAR, Types.VARCHAR, Types.VARCHAR}) == 0)
44
			jdbcTemplate.update(INSERT_HELP, new String[]{help.getName(), help.getText(), help.getId()}, new int[]{Types.VARCHAR, Types.VARCHAR, Types.VARCHAR});
45

  
46
		return help;
47
	}
48

  
49
	public Help getById(String id) {
50
		return new JdbcTemplate(dataSource).queryForObject(GET_BY_ID, new String[]{id}, new int[]{Types.VARCHAR}, helpRowMapper);
51
	}
52

  
53
	public List<Help> getAll() {
54
		return new JdbcTemplate(dataSource).query(GET_ALL, helpRowMapper);
55
	}
56

  
57
	public void delete(String helpId) {
58
		new JdbcTemplate(dataSource).update(DELETE, new String[]{helpId}, new int[]{Types.VARCHAR});
59
	}
60
}
modules/uoa-gwt-widgets/trunk/src/main/java/eu/dnetlib/gwt/shared/Help.java
1
package eu.dnetlib.gwt.shared;
2

  
3
import com.google.gwt.user.client.rpc.IsSerializable;
4

  
5
/**
6
 * Created by antleb on 4/17/15.
7
 */
8
public class Help implements IsSerializable {
9

  
10
	private String id;
11
	private String name;
12
	private String text;
13

  
14
	public Help() {
15
	}
16

  
17
	public Help(String id, String name, String text) {
18
		this.id = id;
19
		this.name = name;
20
		this.text = text;
21
	}
22

  
23
	public String getId() {
24
		return id;
25
	}
26

  
27
	public void setId(String id) {
28
		this.id = id;
29
	}
30

  
31
	public String getName() {
32
		return name;
33
	}
34

  
35
	public void setName(String name) {
36
		this.name = name;
37
	}
38

  
39
	public String getText() {
40
		return text;
41
	}
42

  
43
	public void setText(String text) {
44
		this.text = text;
45
	}
46
}
modules/uoa-gwt-widgets/trunk/src/main/java/eu/dnetlib/gwt/client/ckeditor/CKEditorJSO.java
1
package eu.dnetlib.gwt.client.ckeditor;
2

  
3
import com.google.gwt.core.client.JavaScriptObject;
4

  
5
/**
6
 * Created by stefania on 4/17/15.
7
 */
8
public class CKEditorJSO extends JavaScriptObject {
9

  
10
    protected CKEditorJSO() {}
11

  
12
    public final native void setUiColor(String color) /*-{
13
        this.config.uiColor = color;
14
    }-*/;
15

  
16
    public final native void setData(String data) /*-{
17
        this.setData(data);
18
    }-*/;
19

  
20
    public final native String getData() /*-{
21
        return this.getData();
22
    }-*/;
23

  
24
    public final native void destroy() /*-{
25
        this.destroy();
26
    }-*/;
27
}
modules/uoa-gwt-widgets/trunk/src/main/java/eu/dnetlib/gwt/client/ckeditor/CKEditor.java
1
package eu.dnetlib.gwt.client.ckeditor;
2

  
3
import com.google.gwt.core.client.Callback;
4
import com.google.gwt.core.client.ScriptInjector;
5
import com.google.gwt.user.client.Window;
6

  
7
/**
8
 * Created by stefania on 4/17/15.
9
 */
10
public class CKEditor {
11

  
12
    protected CKEditorJSO editor;
13

  
14
    public CKEditor(final String id, final String color) {
15

  
16
        ScriptInjector.fromUrl("//cdn.ckeditor.com/4.5.7/full/ckeditor.js").setCallback(
17
                new Callback<Void, Exception>() {
18
                    public void onFailure(Exception reason) {
19
                    }
20
                    public void onSuccess(Void result) {
21
                        editor = initCKEditor(id);
22
                        setUIColor(color);
23
                    }
24
                }).setWindow(ScriptInjector.TOP_WINDOW).inject();
25
    }
26

  
27
    public void setValue(String value) {
28
        editor.setData(value);
29
    }
30

  
31
    public String getValue() {
32
        return editor.getData();
33
    }
34

  
35
    public void setUIColor(String value) {
36
        editor.setUiColor(value);
37
    }
38

  
39
    public void destroy() {
40
        editor.destroy();
41
    }
42

  
43
    private native CKEditorJSO initCKEditor(String id) /*-{
44
        return $wnd.CKEDITOR.replace( id );
45
    }-*/;
46
}
modules/uoa-gwt-widgets/trunk/src/main/java/eu/dnetlib/gwt/client/MyFormGroup.java
1
package eu.dnetlib.gwt.client;
2

  
3
import com.google.gwt.user.client.ui.IsWidget;
4
import com.google.gwt.user.client.ui.Widget;
5
import org.gwtbootstrap3.client.ui.FormGroup;
6
import org.gwtbootstrap3.client.ui.FormLabel;
7
import org.gwtbootstrap3.client.ui.InlineHelpBlock;
8
import org.gwtbootstrap3.client.ui.constants.ValidationState;
9

  
10
/**
11
 * Created by stefania on 12/18/15.
12
 */
13
public class MyFormGroup implements IsWidget {
14

  
15
    private FormGroup formGroup = new FormGroup();
16
    private FormLabel formLabel = new FormLabel();
17
    private InlineHelpBlock inlineHelpBlock = new InlineHelpBlock();
18

  
19
    public MyFormGroup(boolean includeHelpBlock, String labelText, Widget... widgets) {
20

  
21
        if(labelText!=null) {
22
            formLabel.setText(labelText);
23
            formGroup.add(formLabel);
24
        }
25

  
26
        if(includeHelpBlock) {
27
            inlineHelpBlock.setVisible(false);
28
            inlineHelpBlock.addStyleName("inline");
29
            formGroup.add(inlineHelpBlock);
30
        }
31

  
32
        for(Widget widget : widgets) {
33
            formGroup.add(widget);
34

  
35
//            formLabel.setFor(widget.getElement().getId());
36
        }
37
    }
38

  
39
    @Override
40
    public Widget asWidget() {
41
        return formGroup;
42
    }
43

  
44
    public void setFormGroupValidationState(ValidationState validationState) {
45
        inlineHelpBlock.setVisible(false);
46
        formGroup.setValidationState(validationState);
47
    }
48

  
49
    public void setLabelText(String labelText) {
50
        formLabel.setText(labelText);
51
    }
52

  
53
    public void displayInlineError(String errorText) {
54
        inlineHelpBlock.setVisible(true);
55
        inlineHelpBlock.setError(errorText);
56
        formGroup.setValidationState(ValidationState.ERROR);
57
    }
58

  
59
    public void displayInlineSuccess(String successText) {
60
        inlineHelpBlock.setVisible(true);
61
        inlineHelpBlock.setText(successText);
62
        formGroup.setValidationState(ValidationState.SUCCESS);
63
    }
64
}
modules/uoa-gwt-widgets/trunk/src/main/java/eu/dnetlib/gwt/client/Widgets.java
1
package eu.dnetlib.gwt.client;
2

  
3
import com.google.gwt.core.client.EntryPoint;
4

  
5
public class Widgets implements EntryPoint {
6

  
7
  /**
8
   * This is the entry point method.
9
   */
10
  public void onModuleLoad() {
11

  
12
  }
13
}
modules/uoa-gwt-widgets/trunk/src/main/java/eu/dnetlib/gwt/client/help/HelpHelper.java
1
package eu.dnetlib.gwt.client.help;
2

  
3
import com.google.gwt.core.client.GWT;
4
import com.google.gwt.dom.client.Document;
5
import com.google.gwt.dom.client.Style;
6
import com.google.gwt.user.client.Window;
7
import com.google.gwt.user.client.rpc.AsyncCallback;
8
import com.google.gwt.user.client.ui.HTML;
9
import com.google.gwt.user.client.ui.RootPanel;
10
import eu.dnetlib.gwt.shared.Help;
11

  
12
/**
13
 * Created by stefania on 4/17/15.
14
 */
15
public abstract class HelpHelper {
16

  
17
    private static HelpServiceAsync helpService = GWT.create(HelpService.class);
18

  
19
    public static void loadHelp(final String helpId, final HelpListener helpListener) {
20

  
21
        helpService.getHelpById(helpId, new AsyncCallback<Help>() {
22

  
23
            @Override
24
            public void onFailure(Throwable throwable) {
25
                Window.alert("help failed");
26
            }
27

  
28
            @Override
29
            public void onSuccess(Help help) {
30

  
31
                Window.alert("help succeeded");
32

  
33
                if(help!=null) {
34

  
35
                    HTML html = new HTML();
36
                    html.setHTML(help.getText());
37

  
38
                    helpListener.helpLoaded(html);
39

  
40
//                    helpPanel.clearContent();
41
//                    helpPanel.addContent(html);
42
//
43
//                    HelpHelper.showSidebar();
44
//                    RootPanel.get("sidebar").add(helpPanel.asWidget());
45
                }
46
            }
47
        });
48
    }
49

  
50
    public interface HelpListener {
51
        void helpLoaded(HTML help);
52
    }
53

  
54
//    public static void showSidebar() {
55
//
56
//        Document.get().getElementById("content").removeClassName("uk-width-medium-1-1");
57
//        Document.get().getElementById("content").addClassName("uk-width-medium-3-4");
58
//        Document.get().getElementById("sidebar").getStyle().setDisplay(Style.Display.BLOCK);
59
//    }
60
//
61
//    public static void hideSidebar() {
62
//
63
//        Document.get().getElementById("content").removeClassName("uk-width-medium-3-4");
64
//        Document.get().getElementById("content").addClassName("uk-width-medium-1-1");
65
//        Document.get().getElementById("sidebar").getStyle().setDisplay(Style.Display.NONE);
66
//    }
67
}
modules/uoa-gwt-widgets/trunk/src/main/java/eu/dnetlib/gwt/client/help/HelpPanel.java
1
package eu.dnetlib.gwt.client.help;
2

  
3
import com.google.gwt.user.client.ui.FlowPanel;
4
import com.google.gwt.user.client.ui.HTML;
5
import com.google.gwt.user.client.ui.IsWidget;
6
import com.google.gwt.user.client.ui.Widget;
7

  
8
/**
9
 * Created by stefania on 3/9/16.
10
 */
11
public class HelpPanel implements IsWidget {
12

  
13
    private FlowPanel helpPanel = new FlowPanel();
14

  
15
    private HTML helpLabel = new HTML();
16

  
17
    public HelpPanel(String title) {
18

  
19
        helpLabel.setHTML("<h3 class=\"uk-panel-title\">" + title + "</h3>");
20

  
21
        helpPanel.add(helpLabel);
22
    }
23

  
24
    @Override
25
    public Widget asWidget() {
26
        return helpPanel;
27
    }
28

  
29
    public void clearContent() {
30
        helpPanel.clear();
31
        helpPanel.add(helpLabel);
32
    }
33

  
34
    public void addContent(IsWidget widget) {
35
        helpPanel.add(widget.asWidget());
36
    }
37

  
38
    public void addStyleName(String styleName) {
39
        helpPanel.addStyleName(styleName);
40
    }
41
}
modules/uoa-gwt-widgets/trunk/src/main/java/eu/dnetlib/gwt/client/help/HelpService.java
1
package eu.dnetlib.gwt.client.help;
2

  
3
import com.google.gwt.user.client.rpc.RemoteService;
4
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
5
import eu.dnetlib.gwt.shared.Help;
6

  
7
import java.util.List;
8

  
9
/**
10
 * Created by stefania on 3/9/16.
11
 */
12
@RemoteServiceRelativePath("springGwtServices/helpService")
13
public interface HelpService extends RemoteService {
14

  
15
    public Help saveHelp(Help help);
16

  
17
    public Help getHelpById(String id);
18

  
19
    public List<Help> getAll();
20

  
21
    public void delete(String helpId);
22
}
modules/uoa-gwt-widgets/trunk/src/main/java/eu/dnetlib/gwt/client/help/AdminWidget.java
1
package eu.dnetlib.gwt.client.help;
2

  
3
import com.google.gwt.core.client.GWT;
4
import com.google.gwt.event.dom.client.ChangeEvent;
5
import com.google.gwt.event.dom.client.ChangeHandler;
6
import com.google.gwt.event.dom.client.ClickEvent;
7
import com.google.gwt.event.dom.client.ClickHandler;
8
import com.google.gwt.i18n.client.DateTimeFormat;
9
import com.google.gwt.user.client.rpc.AsyncCallback;
10
import com.google.gwt.user.client.ui.*;
11
import eu.dnetlib.gwt.client.MyFormGroup;
12
import eu.dnetlib.gwt.client.ckeditor.CKEditor;
13
import eu.dnetlib.gwt.shared.Help;
14
import org.gwtbootstrap3.client.ui.*;
15
import org.gwtbootstrap3.client.ui.Button;
16
import org.gwtbootstrap3.client.ui.Label;
17
import org.gwtbootstrap3.client.ui.ListBox;
18
import org.gwtbootstrap3.client.ui.TextArea;
19
import org.gwtbootstrap3.client.ui.constants.AlertType;
20
import org.gwtbootstrap3.client.ui.constants.ButtonType;
21
import org.gwtbootstrap3.client.ui.constants.FormType;
22

  
23
import java.util.HashMap;
24
import java.util.List;
25
import java.util.Map;
26

  
27
/**
28
 * Created by stefania on 3/9/16.
29
 */
30
public class AdminWidget implements IsWidget {
31

  
32
    private String token = "";
33
    private String uiColor = "#f5f6f8";
34

  
35
    private FlowPanel monitorHelpTextsPagePanel = new FlowPanel();
36
    private Label monitorHelpTextsTitleLabel = new Label();
37
    private Label monitorHelpTextsInfoLabel = new Label();
38

  
39
    private Alert successLabel = new Alert();
40
    private Alert errorLabel = new Alert();
41
    private Alert warningLabel = new Alert();
42

  
43
    private FlowPanel helpTextsPanel = new FlowPanel();
44

  
45
    private Form helpTextsForm = new Form();
46
    private ListBox helpTextsSelection = new ListBox();
47
    private TextArea textArea = new TextArea();
48
    private CKEditor editor;
49

  
50
    private Button submitChanges = new Button();
51
    private Button preview = new Button();
52

  
53
    private FlowPanel previewPanel;
54

  
55
    private Map<String, Help> helpMap = new HashMap<String, Help>();
56

  
57
    private DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy/MM/dd");
58
    private HelpServiceAsync helpService = GWT.create(HelpService.class);
59

  
60
    private HelpTextUpdatedListener helpTextUpdatedListener;
61

  
62
    public AdminWidget(final FlowPanel previewPanel, boolean addButtons) {
63

  
64
        this.previewPanel = previewPanel;
65

  
66
        errorLabel.setType(AlertType.DANGER);
67
        errorLabel.setDismissable(false);
68
        errorLabel.setVisible(false);
69

  
70
        warningLabel.setType(AlertType.WARNING);
71
        warningLabel.setDismissable(false);
72
        warningLabel.setVisible(false);
73

  
74
        successLabel.setType(AlertType.SUCCESS);
75
        successLabel.setDismissable(false);
76
        successLabel.setVisible(false);
77

  
78
        monitorHelpTextsPagePanel.add(successLabel);
79
        monitorHelpTextsPagePanel.add(errorLabel);
80
        monitorHelpTextsPagePanel.add(warningLabel);
81
        monitorHelpTextsPagePanel.add(helpTextsPanel);
82

  
83
        helpTextsSelection.addItem("None selected", "none");
84

  
85
        helpTextsSelection.addChangeHandler(new ChangeHandler() {
86
            @Override
87
            public void onChange(ChangeEvent changeEvent) {
88

  
89
                successLabel.setVisible(false);
90
                errorLabel.setVisible(false);
91
                warningLabel.setVisible(false);
92

  
93
                if(!helpTextsSelection.getSelectedValue().equals("none")) {
94
                    helpService.getHelpById(helpTextsSelection.getSelectedValue(), new AsyncCallback<Help>() {
95

  
96
                        @Override
97
                        public void onFailure(Throwable throwable) {
98

  
99
                            errorLabel.setText("System error retrieving help text");
100
                            errorLabel.setVisible(true);
101
                        }
102

  
103
                        @Override
104
                        public void onSuccess(Help help) {
105

  
106
                            if (help != null)
107
                                editor.setValue(help.getText());
108
                            else
109
                                editor.setValue("");
110

  
111
                        }
112
                    });
113
                } else {
114
                    editor.setValue("");
115
                }
116
            }
117
        });
118
        helpTextsForm.add(new MyFormGroup(false, "Select help item", helpTextsSelection));
119

  
120
        textArea.getElement().setId("editor");
121
        helpTextsForm.add(new MyFormGroup(false, "Edit help text", textArea));
122

  
123
        if(addButtons) {
124

  
125
            preview.setText("Preview");
126
            preview.setType(ButtonType.DEFAULT);
127
            preview.addStyleName("inlineBlock");
128
            preview.addClickHandler(new ClickHandler() {
129

  
130
                @Override
131
                public void onClick(ClickEvent clickEvent) {
132
                    previewHelpText();
133
                }
134
            });
135

  
136
            submitChanges.setText("Submit Changes");
137
            submitChanges.setType(ButtonType.PRIMARY);
138
            submitChanges.addStyleName("inlineBlock");
139
            submitChanges.addClickHandler(new ClickHandler() {
140

  
141
                @Override
142
                public void onClick(ClickEvent clickEvent) {
143
                    saveHelpText();
144
                }
145
            });
146

  
147
            helpTextsForm.add(new MyFormGroup(false, null, preview, submitChanges));
148
        }
149

  
150
        helpTextsPanel.add(helpTextsForm);
151
    }
152

  
153
    public void previewHelpText() {
154

  
155
        if(editor!=null) {
156

  
157
            HTML html = new HTML();
158
            html.setHTML(editor.getValue());
159

  
160
            previewPanel.clear();
161
            previewPanel.add(html);
162
        }
163
    }
164

  
165
    public void saveHelpText() {
166

  
167
        errorLabel.setVisible(false);
168
        warningLabel.setVisible(false);
169
        successLabel.setVisible(false);
170

  
171
        if(!helpTextsSelection.getSelectedValue().equals("none")) {
172

  
173
            Help help = new Help();
174
            help.setId(helpTextsSelection.getSelectedValue());
175
            help.setName(helpMap.get(helpTextsSelection.getSelectedValue()).getName());
176
            help.setText(editor.getValue());
177

  
178
            helpService.saveHelp(help, new AsyncCallback<Help>() {
179

  
180
                @Override
181
                public void onFailure(Throwable throwable) {
182
                    errorLabel.setText("System error saving help text");
183
                    errorLabel.setVisible(true);
184
                }
185

  
186
                @Override
187
                public void onSuccess(Help help) {
188
                    successLabel.setText("Help text saved successfully");
189
                    successLabel.setVisible(true);
190

  
191
                    if(helpTextUpdatedListener!=null)
192
                        helpTextUpdatedListener.helpTextUpdated(help);
193
                }
194
            });
195
        } else {
196
            warningLabel.setText("No help item is selected");
197
            warningLabel.setVisible(true);
198
        }
199
    }
200

  
201
    public interface HelpTextUpdatedListener {
202
        void helpTextUpdated(Help updatedHelp);
203
    }
204

  
205
    public void setHelpTextUpdatedListener(HelpTextUpdatedListener helpTextUpdatedListener) {
206
        this.helpTextUpdatedListener = helpTextUpdatedListener;
207
    }
208

  
209
    public void clear() {
210

  
211
        errorLabel.setVisible(false);
212
        warningLabel.setVisible(false);
213
        successLabel.setVisible(false);
214

  
215
        previewPanel.clear();
216

  
217
        if(editor!=null) {
218
            editor.destroy();
219
            editor = null;
220
        }
221

  
222
        textArea.setValue("");
223
        //TODO
224
//        helpTextsSelection.setSelectedValue("none");
225
    }
226

  
227
    public void reload() {
228
    }
229

  
230
    public void setToken(String token) {
231
        this.token = token;
232
    }
233

  
234
    public void afterAdditionToRootPanel() {
235
        loadHelpTexts();
236
    }
237

  
238
    @Override
239
    public Widget asWidget() {
240
        return monitorHelpTextsPagePanel;
241
    }
242

  
243
    public void setEditorUIColor(String color) {
244
        this.uiColor = color;
245
    }
246

  
247
    public void addStyleName(String styleName) {
248
        monitorHelpTextsPagePanel.addStyleName(styleName);
249
    }
250

  
251
    public void setFormType(FormType formType) {
252
        helpTextsForm.setType(formType);
253
    }
254

  
255
    public void setHelpTexts(List<Help> helpTexts) {
256

  
257
        helpMap.clear();
258
        helpTextsSelection.clear();
259

  
260
        helpTextsSelection.addItem("None selected", "none");
261
        for(Help help : helpTexts) {
262
            helpTextsSelection.addItem(help.getName(), help.getId());
263
            helpMap.put(help.getId(), help);
264
        }
265
    }
266

  
267
    private void loadHelpTexts() {
268

  
269
        if(editor==null) {
270
            editor = new CKEditor(textArea.getElement().getId(), uiColor);
271
        }
272
    }
273
}
modules/uoa-gwt-widgets/trunk/src/main/resources/eu/dnetlib/gwt/client/Messages_fr.properties
1
sendButton = Envoyer
2
nameField = Entrez votre nom
modules/uoa-gwt-widgets/trunk/src/main/webapp/Widgets.html
1
<!doctype html>
2
<!-- The DOCTYPE declaration above will set the    -->
3
<!-- browser's rendering engine into               -->
4
<!-- "Standards Mode". Replacing this declaration  -->
5
<!-- with a "Quirks Mode" doctype may lead to some -->
6
<!-- differences in layout.                        -->
7

  
8
<html>
9
  <head>
10
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
11

  
12
    <!--                                                               -->
13
    <!-- Consider inlining CSS to reduce the number of requested files -->
14
    <!--                                                               -->
15
    <link type="text/css" rel="stylesheet" href="Widgets.css">
16

  
17
    <!--                                           -->
18
    <!-- Any title is fine                         -->
19
    <!--                                           -->
20
    <title>Web Application Starter Project</title>
21

  
22
    <!--                                           -->
23
    <!-- This script loads your compiled module.   -->
24
    <!-- If you add any GWT meta tags, they must   -->
25
    <!-- be added before this line.                -->
26
    <!--                                           -->
27
    <script type="text/javascript" language="javascript" src="Widgets/Widgets.nocache.js"></script>
28
  </head>
29

  
30
  <!--                                           -->
31
  <!-- The body can have arbitrary html, or      -->
32
  <!-- you can leave the body empty if you want  -->
33
  <!-- to create a completely dynamic UI.        -->
34
  <!--                                           -->
35
  <body>
36

  
37
    <!-- OPTIONAL: include this if you want history support -->
38
    <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
39

  
40
    <!-- RECOMMENDED if your web app will not function without JavaScript enabled -->
41
    <noscript>
42
      <div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif">
43
        Your web browser must have JavaScript enabled
44
        in order for this application to display correctly.
45
      </div>
46
    </noscript>
47

  
48
    <h1>Web Application Starter Project</h1>
49

  
50
    <table align="center">
51
      <tr>
52
        <td colspan="2" style="font-weight:bold;">Please enter your name:</td>
53
      </tr>
54
      <tr>
55
        <td id="nameFieldContainer"></td>
56
        <td id="sendButtonContainer"></td>
57
      </tr>
58
      <tr>
59
        <td colspan="2" style="color:red;" id="errorLabelContainer"></td>
60
      </tr>
61
    </table>
62
  </body>
63
</html>
modules/uoa-gwt-widgets/trunk/src/main/webapp/Widgets.css
1
/** Add css rules here for your application. */
2

  
3

  
4
/** Example rules used by the template application (remove for your app) */
5
h1 {
6
  font-size: 2em;
7
  font-weight: bold;
8
  color: #777777;
9
  margin: 40px 0px 70px;
10
  text-align: center;
11
}
12

  
13
.sendButton {
14
  display: block;
15
  font-size: 16pt;
16
}
17

  
18
/** Most GWT widgets already have a style name defined */
19
.gwt-DialogBox {
20
  width: 400px;
21
}
22

  
23
.dialogVPanel {
24
  margin: 5px;
25
}
26

  
27
.serverResponseLabelError {
28
  color: red;
29
}
30

  
31
/** Set ids using widget.getElement().setId("idOfElement") */
32
#closeButton {
33
  margin: 15px 6px 6px;
34
}

Also available in: Unified diff