List of usage examples for org.apache.wicket.markup ComponentTag addBehavior
public final void addBehavior(final Behavior behavior)
From source file:$.ModalLink.java
License:Apache License
@Override protected void onComponentTag(ComponentTag tag) { checkComponentTag(tag, "a"); super.onComponentTag(tag); AttributeModifier href = new AttributeModifier("href", "#" + targetId); AttributeModifier dataToggle = new AttributeModifier("data-toggle", "modal"); tag.addBehavior(href); tag.addBehavior(dataToggle);/*from w w w. j a v a2 s . c o m*/ }
From source file:$.ModalPanel.java
License:Apache License
@Override protected void onComponentTag(ComponentTag tag) { AttributeModifier attr = new AttributeModifier("class", cssClass); tag.addBehavior(attr); super.onComponentTag(tag); }//w w w .j a v a 2 s .c o m
From source file:br.com.digilabs.wicket.bootstrap.BootstrapModalCloseButton.java
License:Apache License
@Override protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); AttributeModifier dataToggle = new AttributeModifier("data-dismiss", "modal"); tag.addBehavior(dataToggle); }
From source file:br.com.digilabs.wicket.bootstrap.BootstrapModalLink.java
License:Apache License
@Override protected void onComponentTag(ComponentTag tag) { checkComponentTag(tag, "a"); super.onComponentTag(tag); AttributeModifier href = new AttributeModifier("href", "#" + targetId); AttributeModifier dataToggle = new AttributeModifier("data-toggle", "modal"); tag.addBehavior(href); tag.addBehavior(dataToggle);//from w w w.j a va 2 s . c o m }
From source file:br.com.digilabs.wicket.bootstrap.BootstrapModalPanel.java
License:Apache License
@Override protected void onComponentTag(ComponentTag tag) { AttributeModifier attr = new AttributeModifier("class", cssClass); tag.addBehavior(attr); super.onComponentTag(tag); }
From source file:org.apache.openmeetings.web.app.MessageTagHandler.java
License:Apache License
@Override protected final MarkupElement onComponentTag(ComponentTag tag) throws ParseException { if (tag.isClose()) { return tag; }/*from ww w . j ava 2 s . c om*/ final String wicketMessageAttribute = tag.getAttributes().getString(getWicketMessageAttrName()); if (Strings.isEmpty(wicketMessageAttribute) == false) { // check if this tag is raw markup if (tag.getId() == null) { // if this is a raw tag we need to set the id to something so // that wicket will not merge this as raw markup and instead // pass it on to a resolver tag.setId(getWicketMessageIdPrefix()); tag.setAutoComponentTag(true); tag.setModified(true); } tag.addBehavior(new AttributeLocalizer(getWicketMessageAttrName())); } return tag; }
From source file:org.geoserver.backuprestore.web.BackupRestoreDataPage.java
License:Open Source License
/** * @param form//from ww w.j a va2s .co m */ @SuppressWarnings({ "unchecked", "rawtypes" }) private void populateBackupForm(Form form) { form.add(new CheckBox("backupOptOverwirte", new Model<Boolean>(false))); form.add(new CheckBox("backupOptBestEffort", new Model<Boolean>(false))); form.add(statusLabel = new Label("status", new Model()).setOutputMarkupId(true)); form.add(new AjaxSubmitLink("newBackupStart", form) { @Override protected void disableLink(ComponentTag tag) { super.disableLink(tag); tag.setName("a"); tag.addBehavior(AttributeModifier.replace("class", "disabled")); } protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(feedbackPanel); } protected void onSubmit(AjaxRequestTarget target, final Form<?> form) { //update status to indicate we are working statusLabel.add(AttributeModifier.replace("class", "working-link")); statusLabel.setDefaultModelObject("Working"); target.add(statusLabel); //enable cancel and disable this Component cancel = form.get("cancel"); cancel.setEnabled(true); target.add(cancel); setEnabled(false); target.add(this); final AjaxSubmitLink self = this; final Long jobid; try { jobid = launchBackupExecution(form); } catch (Exception e) { error(e); LOGGER.log(Level.WARNING, "Error starting a new Backup", e); return; } finally { //update the button back to original state resetButtons(form, target, "newBackupStart"); target.add(feedbackPanel); } cancel.setDefaultModelObject(jobid); this.add(new AbstractAjaxTimerBehavior(Duration.milliseconds(100)) { @Override protected void onTimer(AjaxRequestTarget target) { Backup backupFacade = BackupRestoreWebUtils.backupFacade(); BackupExecutionAdapter exec = backupFacade.getBackupExecutions().get(jobid); if (!exec.isRunning()) { try { if (exec.getAllFailureExceptions() != null && !exec.getAllFailureExceptions().isEmpty()) { getSession().error(exec.getAllFailureExceptions().get(0)); setResponsePage(BackupRestoreDataPage.class); } else if (exec.isStopping()) { //do nothing } else { PageParameters pp = new PageParameters(); pp.add("id", exec.getId()); pp.add("clazz", BackupExecutionAdapter.class.getSimpleName()); setResponsePage(BackupRestorePage.class, pp); } } catch (Exception e) { error(e); LOGGER.log(Level.WARNING, "", e); } finally { stop(null); //update the button back to original state resetButtons(form, target, "newBackupStart"); target.add(feedbackPanel); } return; } String msg = exec != null ? exec.getStatus().toString() : "Working"; statusLabel.setDefaultModelObject(msg); target.add(statusLabel); }; @Override public boolean canCallListenerInterface(Component component, Method method) { if (self.equals(component) && method.getDeclaringClass() .equals(org.apache.wicket.behavior.IBehaviorListener.class) && method.getName().equals("onRequest")) { return true; } return super.canCallListenerInterface(component, method); } }); } private Long launchBackupExecution(Form<?> form) throws Exception { ResourceFilePanel panel = (ResourceFilePanel) newBackupRestorePanel.get("backupResource"); Resource archiveFile = null; try { archiveFile = panel.getResource(); } catch (NullPointerException e) { throw new Exception("Backup Archive File is Mandatory!"); } if (archiveFile == null || archiveFile.getType() == Type.DIRECTORY || FilenameUtils.getExtension(archiveFile.name()).isEmpty()) { throw new Exception("Backup Archive File is Mandatory and should not be a Directory or URI."); } Filter filter = null; WorkspaceInfo ws = (WorkspaceInfo) workspace.getObject(); if (ws != null) { filter = ECQL.toFilter("name = '" + ws.getName() + "'"); } Hints hints = new Hints(new HashMap(2)); Boolean backupOptOverwirte = ((CheckBox) form.get("backupOptOverwirte")).getModelObject(); Boolean backupOptBestEffort = ((CheckBox) form.get("backupOptBestEffort")).getModelObject(); if (backupOptBestEffort) { hints.add(new Hints(new Hints.OptionKey(Backup.PARAM_BEST_EFFORT_MODE), Backup.PARAM_BEST_EFFORT_MODE)); } Backup backupFacade = BackupRestoreWebUtils.backupFacade(); return backupFacade.runBackupAsync(archiveFile, backupOptOverwirte, filter, hints).getId(); } }); form.add(new AjaxLink<Long>("cancel", new Model<Long>()) { protected void disableLink(ComponentTag tag) { super.disableLink(tag); tag.setName("a"); tag.addBehavior(AttributeModifier.replace("class", "disabled")); }; @Override public void onClick(AjaxRequestTarget target) { Long jobid = getModelObject(); if (jobid != null) { try { BackupRestoreWebUtils.backupFacade().stopExecution(jobid); setResponsePage(BackupRestoreDataPage.class); } catch (NoSuchJobExecutionException | JobExecutionNotRunningException e) { LOGGER.log(Level.WARNING, "", e); } } setEnabled(false); target.add(this); } }.setOutputMarkupId(true).setEnabled(false)); backupRestoreExecutionsTable = new BackupRestoreExecutionsTable("backups", new BackupRestoreExecutionsProvider(true, BackupExecutionAdapter.class) { @Override protected List<org.geoserver.web.wicket.GeoServerDataProvider.Property<AbstractExecutionAdapter>> getProperties() { return Arrays.asList(ID, STATE, STARTED, PROGRESS, ARCHIVEFILE, OPTIONS); } }, true, BackupExecutionAdapter.class) { protected void onSelectionUpdate(AjaxRequestTarget target) { }; }; backupRestoreExecutionsTable.setOutputMarkupId(true); backupRestoreExecutionsTable.setFilterable(false); backupRestoreExecutionsTable.setSortable(false); form.add(backupRestoreExecutionsTable); }
From source file:org.geoserver.backuprestore.web.BackupRestoreDataPage.java
License:Open Source License
/** * @param form/*from ww w . j ava2 s .c o m*/ */ @SuppressWarnings({ "rawtypes", "unchecked" }) private void populateRestoreForm(Form form) { form.add(new CheckBox("restoreOptDryRun", new Model<Boolean>(false))); form.add(new CheckBox("restoreOptBestEffort", new Model<Boolean>(false))); form.add(statusLabel = new Label("status", new Model()).setOutputMarkupId(true)); form.add(new AjaxSubmitLink("newRestoreStart", form) { @Override protected void disableLink(ComponentTag tag) { super.disableLink(tag); tag.setName("a"); tag.addBehavior(AttributeModifier.replace("class", "disabled")); } protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(feedbackPanel); } protected void onSubmit(AjaxRequestTarget target, final Form<?> form) { //update status to indicate we are working statusLabel.add(AttributeModifier.replace("class", "working-link")); statusLabel.setDefaultModelObject("Working"); target.add(statusLabel); //enable cancel and disable this Component cancel = form.get("cancel"); cancel.setEnabled(true); target.add(cancel); setEnabled(false); target.add(this); final AjaxSubmitLink self = this; final Long jobid; try { jobid = launchRestoreExecution(form); } catch (Exception e) { error(e); LOGGER.log(Level.WARNING, "Error starting a new Restore", e); return; } finally { //update the button back to original state resetButtons(form, target, "newRestoreStart"); target.add(feedbackPanel); } cancel.setDefaultModelObject(jobid); this.add(new AbstractAjaxTimerBehavior(Duration.milliseconds(100)) { @Override protected void onTimer(AjaxRequestTarget target) { Backup backupFacade = BackupRestoreWebUtils.backupFacade(); RestoreExecutionAdapter exec = backupFacade.getRestoreExecutions().get(jobid); if (!exec.isRunning()) { try { if (exec.getAllFailureExceptions() != null && !exec.getAllFailureExceptions().isEmpty()) { getSession().error(exec.getAllFailureExceptions().get(0)); setResponsePage(BackupRestoreDataPage.class); } else if (exec.isStopping()) { //do nothing } else { PageParameters pp = new PageParameters(); pp.add("id", exec.getId()); pp.add("clazz", RestoreExecutionAdapter.class.getSimpleName()); setResponsePage(BackupRestorePage.class, pp); } } catch (Exception e) { error(e); LOGGER.log(Level.WARNING, "", e); } finally { stop(null); //update the button back to original state resetButtons(form, target, "newRestoreStart"); target.add(feedbackPanel); } return; } String msg = exec != null ? exec.getStatus().toString() : "Working"; statusLabel.setDefaultModelObject(msg); target.add(statusLabel); }; @Override public boolean canCallListenerInterface(Component component, Method method) { if (self.equals(component) && method.getDeclaringClass() .equals(org.apache.wicket.behavior.IBehaviorListener.class) && method.getName().equals("onRequest")) { return true; } return super.canCallListenerInterface(component, method); } }); } private Long launchRestoreExecution(Form<?> form) throws Exception { ResourceFilePanel panel = (ResourceFilePanel) newBackupRestorePanel.get("backupResource"); Resource archiveFile = null; try { archiveFile = panel.getResource(); } catch (NullPointerException e) { throw new Exception("Restore Archive File is Mandatory!"); } if (archiveFile == null || !Resources.exists(archiveFile) || archiveFile.getType() == Type.DIRECTORY || FilenameUtils.getExtension(archiveFile.name()).isEmpty()) { throw new Exception( "Restore Archive File is Mandatory, must exists and should not be a Directory or URI."); } Filter filter = null; WorkspaceInfo ws = (WorkspaceInfo) workspace.getObject(); if (ws != null) { filter = ECQL.toFilter("name = '" + ws.getName() + "'"); } Hints hints = new Hints(new HashMap(2)); Boolean restoreOptDryRun = ((CheckBox) form.get("restoreOptDryRun")).getModelObject(); if (restoreOptDryRun) { hints.add(new Hints(new Hints.OptionKey(Backup.PARAM_DRY_RUN_MODE), Backup.PARAM_DRY_RUN_MODE)); } Boolean restoreOptBestEffort = ((CheckBox) form.get("restoreOptBestEffort")).getModelObject(); if (restoreOptBestEffort) { hints.add(new Hints(new Hints.OptionKey(Backup.PARAM_BEST_EFFORT_MODE), Backup.PARAM_BEST_EFFORT_MODE)); } Backup backupFacade = BackupRestoreWebUtils.backupFacade(); return backupFacade.runRestoreAsync(archiveFile, filter, hints).getId(); } }); form.add(new AjaxLink<Long>("cancel", new Model<Long>()) { protected void disableLink(ComponentTag tag) { super.disableLink(tag); tag.setName("a"); tag.addBehavior(AttributeModifier.replace("class", "disabled")); }; @Override public void onClick(AjaxRequestTarget target) { Long jobid = getModelObject(); if (jobid != null) { try { BackupRestoreWebUtils.backupFacade().stopExecution(jobid); setResponsePage(BackupRestoreDataPage.class); } catch (NoSuchJobExecutionException | JobExecutionNotRunningException e) { LOGGER.log(Level.WARNING, "", e); } } setEnabled(false); target.add(this); } }.setOutputMarkupId(true).setEnabled(false)); restoreExecutionsTable = new BackupRestoreExecutionsTable("restores", new BackupRestoreExecutionsProvider(true, RestoreExecutionAdapter.class) { @Override protected List<org.geoserver.web.wicket.GeoServerDataProvider.Property<AbstractExecutionAdapter>> getProperties() { return Arrays.asList(ID, STATE, STARTED, PROGRESS, ARCHIVEFILE, OPTIONS); } }, true, RestoreExecutionAdapter.class) { protected void onSelectionUpdate(AjaxRequestTarget target) { }; }; restoreExecutionsTable.setOutputMarkupId(true); restoreExecutionsTable.setFilterable(false); restoreExecutionsTable.setSortable(false); form.add(restoreExecutionsTable); }
From source file:org.geoserver.backuprestore.web.BackupRestorePage.java
License:Open Source License
void initComponents(final IModel<T> model) { add(new Label("id", new PropertyModel(model, "id"))); add(new Label("clazz", new Model( this.clazz.getSimpleName().substring(0, this.clazz.getSimpleName().indexOf("Execution"))))); BackupRestoreExecutionsProvider provider = new BackupRestoreExecutionsProvider(getType()) { @Override/*from www. ja va 2 s . c om*/ protected List<Property<AbstractExecutionAdapter>> getProperties() { return Arrays.asList(ID, STATE, STARTED, PROGRESS, ARCHIVEFILE, OPTIONS); } @Override protected List<T> getItems() { return Collections.singletonList(model.getObject()); } }; final BackupRestoreExecutionsTable headerTable = new BackupRestoreExecutionsTable("header", provider, getType()); headerTable.setOutputMarkupId(true); headerTable.setFilterable(false); headerTable.setPageable(false); add(headerTable); final T bkp = model.getObject(); boolean selectable = bkp.getStatus() != BatchStatus.COMPLETED; add(new Icon("icon", COMPRESS_ICON)); add(new Label("title", new DataTitleModel(bkp)) .add(new AttributeModifier("title", new DataTitleModel(bkp, false)))); @SuppressWarnings("rawtypes") Form<?> form = new Form("form"); add(form); try { if (params != null && params.getNamedKeys().contains(DETAILS_LEVEL)) { if (params.get(DETAILS_LEVEL).toInt() > 0) { expand = params.get(DETAILS_LEVEL).toInt(); } } } catch (Exception e) { LOGGER.log(Level.WARNING, "Error parsing the 'details level' parameter: ", params.get(DETAILS_LEVEL).toString()); } form.add(new SubmitLink("refresh") { @Override public void onSubmit() { setResponsePage(BackupRestorePage.class, new PageParameters().add("id", params.get("id").toLong()) .add("clazz", getType().getSimpleName()).add(DETAILS_LEVEL, expand)); } }); NumberTextField<Integer> expand = new NumberTextField<Integer>("expand", new PropertyModel<Integer>(this, "expand")); expand.add(RangeValidator.minimum(0)); form.add(expand); TextArea<String> details = new TextArea<String>("details", new BKErrorDetailsModel(bkp)); details.setOutputMarkupId(true); details.setMarkupId("details"); add(details); String location = bkp.getArchiveFile().path(); if (location == null) { location = getGeoServerApplication().getGeoServer().getLogging().getLocation(); } backupFile = new File(location); if (!backupFile.isAbsolute()) { // locate the geoserver.log file GeoServerDataDirectory dd = getGeoServerApplication().getBeanOfType(GeoServerDataDirectory.class); backupFile = dd.get(Paths.convert(backupFile.getPath())).file(); } if (!backupFile.exists()) { error("Could not find the Backup Archive file: " + backupFile.getAbsolutePath()); } /*** * DOWNLOAD LINK */ final Link<Object> downLoadLink = new Link<Object>("download") { @Override public void onClick() { IResourceStream stream = new FileResourceStream(backupFile) { public String getContentType() { return "application/zip"; } }; ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(stream, backupFile.getName()); handler.setContentDisposition(ContentDisposition.ATTACHMENT); RequestCycle.get().scheduleRequestHandlerAfterCurrent(handler); } }; add(downLoadLink); /*** * PAUSE LINK */ final AjaxLink pauseLink = new AjaxLink("pause") { @Override protected void disableLink(ComponentTag tag) { super.disableLink(tag); tag.setName("a"); tag.addBehavior(AttributeModifier.replace("class", "disabled")); } @Override public void onClick(AjaxRequestTarget target) { AbstractExecutionAdapter bkp = model.getObject(); if (bkp.getStatus() == BatchStatus.STOPPED) { setLinkEnabled((AjaxLink) downLoadLink.getParent().get("pause"), false, target); } else { try { backupFacade().stopExecution(bkp.getId()); setResponsePage(BackupRestoreDataPage.class); } catch (NoSuchJobExecutionException | JobExecutionNotRunningException e) { LOGGER.log(Level.WARNING, "", e); getSession().error(e); setResponsePage(BackupRestoreDataPage.class); } } } }; pauseLink.setEnabled(doSelectReady(bkp) && bkp.getStatus() != BatchStatus.STOPPED); add(pauseLink); /*** * RESUME LINK */ final AjaxLink resumeLink = new AjaxLink("resume") { @Override protected void disableLink(ComponentTag tag) { super.disableLink(tag); tag.setName("a"); tag.addBehavior(AttributeModifier.replace("class", "disabled")); } @Override public void onClick(AjaxRequestTarget target) { AbstractExecutionAdapter bkp = model.getObject(); if (bkp.getStatus() != BatchStatus.STOPPED) { setLinkEnabled((AjaxLink) downLoadLink.getParent().get("pause"), false, target); } else { try { Long id = backupFacade().restartExecution(bkp.getId()); PageParameters pp = new PageParameters(); pp.add("id", id); if (bkp instanceof BackupExecutionAdapter) { pp.add("clazz", BackupExecutionAdapter.class.getSimpleName()); } else if (bkp instanceof RestoreExecutionAdapter) { pp.add("clazz", RestoreExecutionAdapter.class.getSimpleName()); } setResponsePage(BackupRestorePage.class, pp); } catch (NoSuchJobExecutionException | JobInstanceAlreadyCompleteException | NoSuchJobException | JobRestartException | JobParametersInvalidException e) { LOGGER.log(Level.WARNING, "", e); getSession().error(e); setResponsePage(BackupRestoreDataPage.class); } } } }; resumeLink.setEnabled(bkp.getStatus() == BatchStatus.STOPPED); add(resumeLink); /*** * ABANDON LINK */ final AjaxLink cancelLink = new AjaxLink("cancel") { @Override protected void disableLink(ComponentTag tag) { super.disableLink(tag); tag.setName("a"); tag.addBehavior(AttributeModifier.replace("class", "disabled")); } @Override public void onClick(AjaxRequestTarget target) { AbstractExecutionAdapter bkp = model.getObject(); if (!doSelectReady(bkp)) { setLinkEnabled((AjaxLink) downLoadLink.getParent().get("cancel"), false, target); } else { try { backupFacade().abandonExecution(bkp.getId()); PageParameters pp = new PageParameters(); pp.add("id", bkp.getId()); if (bkp instanceof BackupExecutionAdapter) { pp.add("clazz", BackupExecutionAdapter.class.getSimpleName()); } else if (bkp instanceof RestoreExecutionAdapter) { pp.add("clazz", RestoreExecutionAdapter.class.getSimpleName()); } setResponsePage(BackupRestorePage.class, pp); } catch (NoSuchJobExecutionException | JobExecutionAlreadyRunningException e) { error(e); LOGGER.log(Level.WARNING, "", e); } } } }; cancelLink.setEnabled(doSelectReady(bkp)); add(cancelLink); /*** * DONE LINK */ final AjaxLink doneLink = new AjaxLink("done") { @Override protected void disableLink(ComponentTag tag) { super.disableLink(tag); tag.setName("a"); tag.addBehavior(AttributeModifier.replace("class", "disabled")); } @Override public void onClick(AjaxRequestTarget target) { setResponsePage(BackupRestoreDataPage.class); return; } }; add(doneLink); /** * FINALIZE */ add(dialog = new GeoServerDialog("dialog")); }
From source file:org.geoserver.backuprestore.web.BackupRestoreWebUtils.java
License:Open Source License
static void disableLink(ComponentTag tag) { tag.setName("a"); tag.addBehavior(AttributeModifier.replace("class", "disabled")); }