@Override public CharSequence getBeforeHandler(Component component) { String id = getTextAreaMarkupId(); return "if (document.gsEditors) { document.getElementById('" + id + "').value = document.gsEditors." + id + ".getValue(); }"; } };
public void setRawStyle(Reader in) throws IOException { BufferedReader bin = null; if (in instanceof BufferedReader) { bin = (BufferedReader) in; } else { bin = new BufferedReader(in); } StringBuilder builder = new StringBuilder(); String line = null; while ((line = bin.readLine()) != null) { builder.append(line).append("\n"); } this.rawStyle = builder.toString(); editor.setModelObject(rawStyle); in.close(); }
List<Exception> validateSLD() { try { final String sld = editor.getInput(); ByteArrayInputStream input = new ByteArrayInputStream(sld.getBytes()); List<Exception> validationErrors = Styles.validate(input); return validationErrors; } catch( Exception e ) { return Arrays.asList( e ); } }
new CodeMirrorEditor( "styleEditor", styleHandler().getCodeMirrorEditMode(), new PropertyModel<String>(this, "rawStyle"))); editor.setTextAreaMarkupId("editor"); editor.setMarkupId("style-editor"); editor.setOutputMarkupId(true); editor.setRequired(true); styleForm.add(editor); editor.addCustomButton( new ParamResourceModel("insertImage", getPage()).getString(), "button-picture", }); editor.addCustomButton( new ParamResourceModel("chooseColor", getPage()).getString(), "button-color",
styleForm.add( editor = new CodeMirrorEditor("SLD", new PropertyModel(this, "rawSLD")) ); editor.setTextAreaMarkupId("editor"); editor.setOutputMarkupId(true); editor.setRequired(true); styleForm.add(editor);
public CodeMirrorEditor(String id, IModel<String> model) { super(id, model); container = new WebMarkupContainer("editorContainer"); container.setOutputMarkupId(true); add(container); editor = new TextArea<String>("editor", new Model<String>((String) model.getObject())); container.add(editor); editor.setOutputMarkupId(true); editor.add(new CodeMirrorBehavior()); }
demoRequestsForm.add(urlTextField); body = new CodeMirrorEditor("body", new PropertyModel(requestModel, "requestBody")); body.setTextAreaMarkupId("requestBody");
public CodeMirrorEditor(String id, String mode, IModel<String> model) { super(id, model); this.mode = mode; // figure out if we're running against a browser supported by CodeMirror boolean enableCodeMirror = isCodeMirrorSupported(); container = new WebMarkupContainer("editorContainer"); container.setOutputMarkupId(true); add(container); WebMarkupContainer toolbar = new WebMarkupContainer("toolbar"); toolbar.setVisible(enableCodeMirror); container.add(toolbar); customButtons = new RepeatingView("custom-buttons"); toolbar.add(customButtons); WebMarkupContainer editorParent = new WebMarkupContainer("editorParent"); if (enableCodeMirror) { editorParent.add( AttributeModifier.replace( "style", "border: 1px solid black; padding-bottom: 3px")); } container.add(editorParent); editor = new TextArea<String>("editor", model); editorParent.add(editor); editor.setOutputMarkupId(true); if (enableCodeMirror) { editor.add(new CodeMirrorBehavior()); } else { editor.add(AttributeModifier.replace("style", "width:100%")); } }
@Override protected void onClick(AjaxRequestTarget target, Form<?> form) { stylePage.editor.processInput(); wsChoice.processInput(); styleResource = dd.style(si); try (OutputStream os = styleResource.out()) { IOUtils.write(stylePage.editor.getInput(), os); Styles.handler(format).version(stylePage.editor.getInput()); si.setFormatVersion(version); Style style = dd.parsedStyle(si);
@Override protected void onSubmit(AjaxRequestTarget target, Form form) { // we need to force validation or the value won't be converted styles.processInput(); StyleInfo style = (StyleInfo) styles.getConvertedInput(); if (style != null) { try { // same here, force validation or the field won't be udpated editor.reset(); setRawSLD(readFile(style)); } catch (Exception e) { error("Errors occurred loading the '" + style.getName() + "' style"); } target.addComponent(styleForm); } }
try { stylePage.editor.reset(); stylePage.setRawStyle( new StringReader( } catch (Exception e) { clearFeedbackMessages(); stylePage.editor.getFeedbackMessages().clear(); stylePage.error("Errors occurred generating the style"); LOGGER.log(Level.WARNING, "Errors occured generating the style", e);
@Override protected IAjaxCallDecorator getAjaxCallDecorator() { return editor.getSaveDecorator(); }; };
@Override public void convertInput() { editor.processInput(); setConvertedInput(editor.getConvertedInput()); }
@Override protected void onClick(AjaxRequestTarget target, Form form) { editor.processInput(); List<Exception> errors = validateSLD(); if ( errors.isEmpty() ) { form.info( "No validation errors."); } else { for( Exception e : errors ) { form.error( sldErrorWithLineNo(e) ); } } }
styleForm.setEnabled(false); editor.add(new AttributeAppender("class", new Model<String>("disabled"), " ")); get("validate") .add(
try { IOUtils.copy(upload.getInputStream(), bout); stylePage.editor.reset(); stylePage.setRawStyle( new InputStreamReader(
@Override protected void updateAjaxAttributes(AjaxRequestAttributes attributes) { super.updateAjaxAttributes(attributes); attributes.getAjaxCallListeners().add(stylePage.editor.getSaveDecorator()); } };
@Override protected void convertInput() { editor.processInput(); setConvertedInput(editor.getConvertedInput()); }
uploadForm.setEnabled(false); editor.add(new AttributeAppender("class", new Model("disabled"), " ")); get("validate").add(new AttributeAppender("style", new Model("display:none;"), " ")); add(new AbstractBehavior() {
public void setRawSLD(Reader in) throws IOException { BufferedReader bin = null; if ( in instanceof BufferedReader ) { bin = (BufferedReader) in; } else { bin = new BufferedReader( in ); } StringBuilder builder = new StringBuilder(); String line = null; while ((line = bin.readLine()) != null ) { builder.append(line).append("\n"); } this.rawSLD = builder.toString(); editor.setModelObject(rawSLD); in.close(); }