Example usage for org.apache.wicket Component setEnabled

List of usage examples for org.apache.wicket Component setEnabled

Introduction

In this page you can find the example usage for org.apache.wicket Component setEnabled.

Prototype

public final Component setEnabled(final boolean enabled) 

Source Link

Document

Sets whether this component is enabled.

Usage

From source file:org.devgateway.eudevfin.ui.common.events.MarkersField13UpdateBehavior.java

License:Open Source License

@Override
protected void onEventExtra(Component component, IEvent<?> event) {
    if (!component.getParent().getParent().getParent().getParent().isVisibleInHierarchy())
        return;/* w  w w . j  a va 2 s.co m*/
    Field13ChangedEventPayload eventPayload = getEventPayload(event);
    if (pattern.matcher(eventPayload.getField13Code()).matches()) {
        component.setEnabled(false);
        component.setDefaultModelObject(null);
    }

    else
        component.setEnabled(true);
}

From source file:org.devgateway.toolkit.forms.wicket.components.ComponentUtil.java

License:Open Source License

public static void enableDisableEvent(final Component c, final IEvent<?> event) {
    if (event.getPayload() instanceof EditingDisabledEvent) {
        c.setEnabled(false);
    }// w  ww  .j a  v a  2 s. c o m

    if (event.getPayload() instanceof EditingEnabledEvent) {
        c.setEnabled(true);
    }

}

From source file:org.geoserver.backuprestore.web.BackupRestoreDataPage.java

License:Open Source License

/**
 * @param form/*w w w. j a v  a  2 s.  c o 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   w w w . jav  a 2s .c  om*/
 */
@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.community.css.web.CssDemoPage.java

License:Open Source License

private void doMainLayout() {
    final Fragment mainContent = new Fragment("main-content", "normal", this);

    final ModalWindow popup = new ModalWindow("popup");
    mainContent.add(popup);//from  w  w  w .jav a  2  s. co  m
    final StyleNameModel styleNameModel = new StyleNameModel(style);
    final PropertyModel layerNameModel = new PropertyModel(layer, "prefixedName");

    mainContent.add(new AjaxLink("create.style", new ParamResourceModel("CssDemoPage.createStyle", this)) {
        public void onClick(AjaxRequestTarget target) {
            target.appendJavascript("Wicket.Window.unloadConfirmation = false;");
            popup.setInitialHeight(200);
            popup.setInitialWidth(300);
            popup.setTitle(new Model("Choose name for new style"));
            popup.setContent(new StyleNameInput(popup.getContentId(), CssDemoPage.this));
            popup.show(target);
        }
    });

    mainContent.add(new SimpleAjaxLink("change.style", styleNameModel) {
        public void onClick(AjaxRequestTarget target) {
            target.appendJavascript("Wicket.Window.unloadConfirmation = false;");
            popup.setInitialHeight(400);
            popup.setInitialWidth(600);
            popup.setTitle(new Model("Choose style to edit"));
            popup.setContent(new StyleChooser(popup.getContentId(), CssDemoPage.this));
            popup.show(target);
        }
    });
    mainContent.add(new SimpleAjaxLink("change.layer", layerNameModel) {
        public void onClick(AjaxRequestTarget target) {
            target.appendJavascript("Wicket.Window.unloadConfirmation = false;");
            popup.setInitialHeight(400);
            popup.setInitialWidth(600);
            popup.setTitle(new Model("Choose layer to edit"));
            popup.setContent(new LayerChooser(popup.getContentId(), CssDemoPage.this));
            popup.show(target);
        }
    });
    mainContent
            .add(new AjaxLink("associate.styles", new ParamResourceModel("CssDemoPage.associateStyles", this)) {
                public void onClick(AjaxRequestTarget target) {
                    target.appendJavascript("Wicket.Window.unloadConfirmation = false;");
                    popup.setInitialHeight(400);
                    popup.setInitialWidth(600);
                    popup.setTitle(new Model("Choose layers to associate"));
                    popup.setContent(new MultipleLayerChooser(popup.getContentId(), CssDemoPage.this));
                    popup.show(target);
                }
            });
    ParamResourceModel associateToLayer = new ParamResourceModel("CssDemoPage.associateDefaultStyle", this,
            styleNameModel, layerNameModel);
    final SimpleAjaxLink associateDefaultStyle = new SimpleAjaxLink("associate.default.style", new Model(),
            associateToLayer) {
        public void onClick(final AjaxRequestTarget linkTarget) {
            final Component theComponent = this;
            dialog.setResizable(false);
            dialog.setHeightUnit("em");
            dialog.setWidthUnit("em");
            dialog.setInitialHeight(7);
            dialog.setInitialWidth(50);
            dialog.showOkCancel(linkTarget, new DialogDelegate() {
                boolean success = false;

                @Override
                protected boolean onSubmit(AjaxRequestTarget target, Component contents) {
                    layer.setDefaultStyle(style);
                    getCatalog().save(layer);
                    theComponent.setEnabled(false);
                    success = true;
                    return true;
                }

                @Override
                public void onClose(AjaxRequestTarget target) {
                    super.onClose(target);
                    target.addComponent(theComponent);
                    if (success) {
                        CssDemoPage.this.info(new ParamResourceModel("CssDemoPage.styleAssociated",
                                CssDemoPage.this, styleNameModel, layerNameModel).getString());
                        target.addComponent(getFeedbackPanel());
                    }
                }

                @Override
                protected Component getContents(String id) {
                    ParamResourceModel confirm = new ParamResourceModel("CssDemoPage.confirmAssocation",
                            CssDemoPage.this, styleNameModel.getObject(), layerNameModel.getObject(),
                            layer.getDefaultStyle().getName());
                    return new Label(id, confirm);
                }
            });
        }
    };
    associateDefaultStyle.setOutputMarkupId(true);
    if (layer.getDefaultStyle().equals(style)) {
        associateDefaultStyle.setEnabled(false);
    }

    mainContent.add(associateDefaultStyle);

    final IModel<String> sldModel = new AbstractReadOnlyModel<String>() {
        public String getObject() {
            try {
                // if file already in css format transform to sld, otherwise load the SLD file
                if (CssHandler.FORMAT.equals(style.getFormat())) {
                    StyledLayerDescriptor sld = Styles.sld(style.getStyle());
                    return Styles.string(sld, new SLDHandler(), SLDHandler.VERSION_10, true);
                } else {
                    File file = findStyleFile(style);
                    if (file != null && file.isFile()) {
                        BufferedReader reader = null;
                        try {
                            reader = new BufferedReader(new FileReader(file));
                            StringBuilder builder = new StringBuilder();
                            char[] line = new char[4096];
                            int len = 0;
                            while ((len = reader.read(line, 0, 4096)) >= 0)
                                builder.append(line, 0, len);
                            return builder.toString();
                        } finally {
                            if (reader != null)
                                reader.close();
                        }
                    } else {
                        return "No SLD file found for this style. One will be generated automatically if you save the CSS.";
                    }
                }
            } catch (IOException e) {
                throw new WicketRuntimeException(e);
            }
        }
    };

    final CompoundPropertyModel model = new CompoundPropertyModel<CssDemoPage>(CssDemoPage.this);
    List<ITab> tabs = new ArrayList<ITab>();
    tabs.add(new PanelCachingTab(new AbstractTab(new Model("Generated SLD")) {
        public Panel getPanel(String id) {
            SLDPreviewPanel panel = new SLDPreviewPanel(id, sldModel);
            sldPreview = panel.getLabel();
            return panel;
        }
    }));
    tabs.add(new PanelCachingTab(new AbstractTab(new Model("Map")) {
        public Panel getPanel(String id) {
            return map = new OpenLayersMapPanel(id, layer, style);
        }
    }));
    if (layer.getResource() instanceof FeatureTypeInfo) {
        tabs.add(new PanelCachingTab(new AbstractTab(new Model("Data")) {
            public Panel getPanel(String id) {
                try {
                    return new DataPanel(id, model, (FeatureTypeInfo) layer.getResource());
                } catch (IOException e) {
                    throw new WicketRuntimeException(e);
                }
            };
        }));
    } else if (layer.getResource() instanceof CoverageInfo) {
        tabs.add(new PanelCachingTab(new AbstractTab(new Model("Data")) {
            public Panel getPanel(String id) {
                return new BandsPanel(id, (CoverageInfo) layer.getResource());
            };
        }));
    }
    tabs.add(new AbstractTab(new Model("CSS Reference")) {
        public Panel getPanel(String id) {
            return new DocsPanel(id);
        }
    });

    File sldFile = findStyleFile(style);
    File cssFile = new File(sldFile.getParentFile(), style.getName() + ".css");

    mainContent.add(new StylePanel("style.editing", model, CssDemoPage.this, cssFile));

    mainContent.add(new AjaxTabbedPanel("context", tabs));

    add(mainContent);
    add(dialog = new GeoServerDialog("dialog"));
}

From source file:org.geoserver.importer.web.ImportDataPage.java

License:Open Source License

public ImportDataPage(PageParameters params) {
    Form form = new Form("form");
    add(form);//from w w  w .  j  a  v a2  s.co  m

    sourceList = new AjaxRadioPanel<Source>("sources", Arrays.asList(Source.values()), Source.SPATIAL_FILES) {
        @Override
        protected void onRadioSelect(AjaxRequestTarget target, Source newSelection) {
            updateSourcePanel(newSelection, target);
        }

        @Override
        protected AjaxRadio<Source> newRadioCell(RadioGroup<Source> group, ListItem<Source> item) {
            AjaxRadio<Source> radio = super.newRadioCell(group, item);
            if (!item.getModelObject().isAvailable()) {
                radio.setEnabled(false);
            }
            return radio;
        }

        @Override
        protected Component createLabel(String id, ListItem<Source> item) {
            return new SourceLabelPanel(id, item.getModelObject());
        }
    };

    form.add(sourceList);

    sourcePanel = new WebMarkupContainer("panel");
    sourcePanel.setOutputMarkupId(true);
    form.add(sourcePanel);

    Catalog catalog = GeoServerApplication.get().getCatalog();

    // workspace chooser
    workspace = new WorkspaceDetachableModel(catalog.getDefaultWorkspace());
    workspaceChoice = new DropDownChoice("workspace", workspace, new WorkspacesModel(),
            new WorkspaceChoiceRenderer());
    workspaceChoice.setOutputMarkupId(true);
    workspaceChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            updateTargetStore(target);
        }
    });
    workspaceChoice.setNullValid(true);
    form.add(workspaceChoice);

    WebMarkupContainer workspaceNameContainer = new WebMarkupContainer("workspaceNameContainer");
    workspaceNameContainer.setOutputMarkupId(true);
    form.add(workspaceNameContainer);

    workspaceNameTextField = new TextField("workspaceName", new Model());
    workspaceNameTextField.setOutputMarkupId(true);
    boolean defaultWorkspace = catalog.getDefaultWorkspace() != null;
    workspaceNameTextField.setVisible(!defaultWorkspace);
    workspaceNameTextField.setRequired(!defaultWorkspace);
    workspaceNameContainer.add(workspaceNameTextField);

    //store chooser
    WorkspaceInfo ws = (WorkspaceInfo) workspace.getObject();
    store = new StoreModel(ws != null ? catalog.getDefaultDataStore(ws) : null);
    storeChoice = new DropDownChoice("store", store, new EnabledStoresModel(workspace),
            new StoreChoiceRenderer()) {
        protected String getNullValidKey() {
            return ImportDataPage.class.getSimpleName() + "." + super.getNullValidKey();
        };
    };
    storeChoice.setOutputMarkupId(true);

    storeChoice.setNullValid(true);
    form.add(storeChoice);

    form.add(statusLabel = new Label("status", new Model()).setOutputMarkupId(true));
    form.add(new AjaxSubmitLink("next", form) {
        @Override
        protected void disableLink(ComponentTag tag) {
            super.disableLink(tag);
            tag.setName("a");
            tag.addBehavior(new SimpleAttributeModifier("class", "disabled"));
        }

        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.addComponent(feedbackPanel);
        }

        protected void onSubmit(AjaxRequestTarget target, final Form<?> form) {

            //update status to indicate we are working
            statusLabel.add(new SimpleAttributeModifier("class", "working-link"));
            statusLabel.setDefaultModelObject("Working");
            target.addComponent(statusLabel);

            //enable cancel and disable this
            Component cancel = form.get("cancel");
            cancel.setEnabled(true);
            target.addComponent(cancel);

            setEnabled(false);
            target.addComponent(this);

            final AjaxSubmitLink self = this;

            final Long jobid;
            try {
                jobid = createContext();
            } catch (Exception e) {
                error(e);
                LOGGER.log(Level.WARNING, "Error creating import", e);
                resetButtons(form, target);
                return;
            }

            cancel.setDefaultModelObject(jobid);
            this.add(new AbstractAjaxTimerBehavior(Duration.seconds(3)) {
                protected void onTimer(AjaxRequestTarget target) {
                    Importer importer = ImporterWebUtils.importer();
                    Task<ImportContext> t = importer.getTask(jobid);

                    if (t.isDone()) {
                        try {
                            if (t.getError() != null) {
                                error(t.getError());
                            } else if (t.isCancelled()) {
                                //do nothing
                            } else {
                                ImportContext imp = t.get();

                                //check the import for actual things to do
                                boolean proceed = !imp.getTasks().isEmpty();

                                if (proceed) {
                                    imp.setArchive(false);
                                    importer.changed(imp);

                                    PageParameters pp = new PageParameters();
                                    pp.put("id", imp.getId());

                                    setResponsePage(ImportPage.class, pp);
                                } else {
                                    info("No data to import was found");
                                    importer.delete(imp);
                                }
                            }
                        } catch (Exception e) {
                            error(e);
                            LOGGER.log(Level.WARNING, "", e);
                        } finally {
                            stop();

                            //update the button back to original state
                            resetButtons(form, target);

                            target.addComponent(feedbackPanel);
                        }
                        return;
                    }

                    ProgressMonitor m = t.getMonitor();
                    String msg = m.getTask() != null ? m.getTask().toString() : "Working";

                    statusLabel.setDefaultModelObject(msg);
                    target.addComponent(statusLabel);
                };
            });
        }
    });

    form.add(new AjaxLink<Long>("cancel", new Model<Long>()) {
        protected void disableLink(ComponentTag tag) {
            super.disableLink(tag);
            ImporterWebUtils.disableLink(tag);
        };

        @Override
        public void onClick(AjaxRequestTarget target) {
            Importer importer = ImporterWebUtils.importer();
            Long jobid = getModelObject();
            Task<ImportContext> task = importer.getTask(jobid);
            if (task != null && !task.isDone() && !task.isCancelled()) {
                task.getMonitor().setCanceled(true);
                task.cancel(false);
                try {
                    task.get();
                } catch (Exception e) {
                }
            }

            setEnabled(false);

            Component next = getParent().get("next");
            next.setEnabled(true);

            target.addComponent(this);
            target.addComponent(next);
        }
    }.setOutputMarkupId(true).setEnabled(false));

    importTable = new ImportContextTable("imports", new ImportContextProvider(true) {
        @Override
        protected List<org.geoserver.web.wicket.GeoServerDataProvider.Property<ImportContext>> getProperties() {
            return Arrays.asList(ID, STATE, UPDATED);
        }
    }, true) {
        protected void onSelectionUpdate(AjaxRequestTarget target) {
            removeImportLink.setEnabled(!getSelection().isEmpty());
            target.addComponent(removeImportLink);
        };
    };
    importTable.setOutputMarkupId(true);
    importTable.setFilterable(false);
    importTable.setSortable(false);
    form.add(importTable);

    form.add(removeImportLink = new AjaxLink("remove") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            Importer importer = ImporterWebUtils.importer();
            for (ImportContext c : importTable.getSelection()) {
                try {
                    importer.delete(c);
                } catch (IOException e) {
                    LOGGER.log(Level.WARNING, "Error deleting context", c);
                }
            }
            importTable.clearSelection();
            target.addComponent(importTable);
        }
    });
    removeImportLink.setOutputMarkupId(true).setEnabled(false);

    AjaxLink jobLink = new AjaxLink("jobs") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            dialog.showOkCancel(target, new DialogDelegate() {
                @Override
                protected boolean onSubmit(AjaxRequestTarget target, Component contents) {
                    return true;
                }

                @Override
                protected Component getContents(String id) {
                    return new JobQueuePanel(id);
                }
            });
        }
    };
    jobLink.setVisible(ImporterWebUtils.isDevMode());
    form.add(jobLink);

    add(dialog = new GeoServerDialog("dialog"));
    dialog.setInitialWidth(600);
    dialog.setInitialHeight(400);
    dialog.setMinimalHeight(150);

    updateSourcePanel(Source.SPATIAL_FILES, null);
    updateTargetStore(null);
}

From source file:org.geoserver.wcs.web.demo.AffineTransformPanel.java

License:Open Source License

public AffineTransformPanel setReadOnly(final boolean readOnly) {
    visitChildren(TextField.class, new org.apache.wicket.Component.IVisitor() {
        public Object component(Component component) {
            component.setEnabled(!readOnly);
            return null;
        }//  ww  w  .  ja va2s  .c o  m
    });

    return this;
}

From source file:org.geoserver.wcs.web.demo.GridPanel.java

License:Open Source License

public GridPanel setReadOnly(final boolean readOnly) {
    visitChildren(TextField.class, new org.apache.wicket.Component.IVisitor() {
        public Object component(Component component) {
            component.setEnabled(!readOnly);
            return null;
        }/*from w  ww .  ja  va  2  s  .co m*/
    });

    return this;
}

From source file:org.geoserver.web.data.layergroup.LayerGroupEditPage.java

License:Open Source License

public LayerGroupEditPage(PageParameters parameters) {
    String groupName = parameters.getString(GROUP);
    String wsName = parameters.getString(WORKSPACE);

    LayerGroupInfo lg = wsName != null ? getCatalog().getLayerGroupByName(wsName, groupName)
            : getCatalog().getLayerGroupByName(groupName);

    if (lg == null) {
        error(new ParamResourceModel("LayerGroupEditPage.notFound", this, groupName).getString());
        doReturn(LayerGroupPage.class);
        return;//  w w w . ja  va 2s . co  m
    }

    initUI(lg);

    if (!isAuthenticatedAsAdmin()) {
        Form f = (Form) get("form");

        //global layer groups only editable by full admin
        if (lg.getWorkspace() == null) {
            //disable all form components but cancel
            f.visitChildren(new IVisitor<Component>() {
                @Override
                public Object component(Component c) {
                    if (!(c instanceof AbstractLink && "cancel".equals(c.getId()))) {
                        c.setEnabled(false);
                    }
                    return CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
                }
            });
            f.get("save").setVisible(false);

            info(new StringResourceModel("globalLayerGroupReadOnly", this, null).getString());
        }

        //always disable the workspace toggle
        f.get("workspace").setEnabled(false);
    }
}

From source file:org.geoserver.web.wicket.EnvelopePanel.java

License:Open Source License

public EnvelopePanel setReadOnly(final boolean readOnly) {
    visitChildren(TextField.class, new org.apache.wicket.Component.IVisitor() {
        public Object component(Component component) {
            component.setEnabled(!readOnly);
            return null;
        }//from   ww w. j  ava  2  s  .  c o m
    });
    crsPanel.setReadOnly(readOnly);

    return this;
}