Search in sources :

Example 6 with LoadableDetachableModel

use of org.apache.wicket.model.LoadableDetachableModel in project hale by halestudio.

the class StatusPage method addControls.

@Override
protected void addControls(boolean loggedIn) {
    super.addControls(loggedIn);
    final String workspaceId = getPageParameters().get(PARAMETER_WORKSPACE).toOptionalString();
    if (workspaceId == null || workspaceId.isEmpty()) {
        throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "Workspace ID not specified.");
    }
    try {
        workspaces.getWorkspaceFolder(workspaceId);
    } catch (FileNotFoundException e) {
        throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "Workspace does not exist.");
    }
    final IModel<TransformationWorkspace> workspace = new LoadableDetachableModel<TransformationWorkspace>() {

        private static final long serialVersionUID = 2600444242247550094L;

        @Override
        protected TransformationWorkspace load() {
            return new TransformationWorkspace(workspaceId);
        }
    };
    // job panel
    final Serializable family = AbstractTransformationJob.createFamily(workspaceId);
    final JobPanel jobs = new JobPanel("jobs", family, true);
    add(jobs);
    // status
    final Label status = new Label("status", new LoadableDetachableModel<String>() {

        private static final long serialVersionUID = -4351763182104835300L;

        @Override
        protected String load() {
            if (workspace.getObject().isTransformationFinished()) {
                if (workspace.getObject().isTransformationSuccessful()) {
                    return "Transformation completed.";
                } else {
                    return "Transformation failed.";
                }
            } else {
                if (Job.getJobManager().find(family).length > 0) {
                    return "Transformation is running:";
                } else {
                    return "No transformation running.";
                }
            }
        }
    });
    status.setOutputMarkupId(true);
    add(status);
    // result
    final WebMarkupContainer result = new WebMarkupContainer("result");
    result.setOutputMarkupId(true);
    add(result);
    final WebMarkupContainer update = new WebMarkupContainer("update") {

        private static final long serialVersionUID = -2591480922683644827L;

        @Override
        public boolean isVisible() {
            return workspace.getObject().isTransformationFinished();
        }
    };
    result.add(update);
    // result : report
    File reportFile = workspace.getObject().getReportFile();
    DownloadLink report = new DownloadLink("log", reportFile, reportFile.getName());
    update.add(report);
    // result : file list
    IModel<? extends List<File>> resultFilesModel = new LoadableDetachableModel<List<File>>() {

        private static final long serialVersionUID = -7971872898614031331L;

        @Override
        protected List<File> load() {
            return Arrays.asList(workspace.getObject().getTargetFolder().listFiles());
        }
    };
    final ListView<File> fileList = new ListView<File>("file", resultFilesModel) {

        private static final long serialVersionUID = -8045643864251639540L;

        @Override
        protected void populateItem(ListItem<File> item) {
            // download link
            DownloadLink download = new DownloadLink("download", item.getModelObject(), item.getModelObject().getName());
            item.add(download);
            // file name
            download.add(new Label("name", item.getModelObject().getName()));
        }
    };
    update.add(fileList);
    // leaseEnd
    String leaseEnd;
    try {
        leaseEnd = workspaces.getLeaseEnd(workspaceId).toString(DateTimeFormat.mediumDateTime());
    } catch (IOException e) {
        leaseEnd = "unknown";
    }
    add(new Label("leaseEnd", leaseEnd));
    boolean transformationFinished = workspace.getObject().isTransformationFinished();
    if (transformationFinished) {
        // disable job timer
        jobs.getTimer().stopOnNextUpdate();
    } else {
        // timer
        add(new AbstractAjaxTimerBehavior(Duration.milliseconds(1500)) {

            private static final long serialVersionUID = -3726349470723024150L;

            @Override
            protected void onTimer(AjaxRequestTarget target) {
                if (workspace.getObject().isTransformationFinished()) {
                    // update status and result
                    target.add(status);
                    target.add(result);
                    // stop timers
                    stop(target);
                    jobs.getTimer().stopOnNextUpdate();
                }
            }
        });
    }
}
Also used : TransformationWorkspace(eu.esdihumboldt.hale.common.headless.transform.TransformationWorkspace) DownloadLink(org.apache.wicket.markup.html.link.DownloadLink) Serializable(java.io.Serializable) AbortWithHttpErrorCodeException(org.apache.wicket.request.http.flow.AbortWithHttpErrorCodeException) FileNotFoundException(java.io.FileNotFoundException) Label(org.apache.wicket.markup.html.basic.Label) IOException(java.io.IOException) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ListView(org.apache.wicket.markup.html.list.ListView) LoadableDetachableModel(org.apache.wicket.model.LoadableDetachableModel) AbstractAjaxTimerBehavior(org.apache.wicket.ajax.AbstractAjaxTimerBehavior) ListItem(org.apache.wicket.markup.html.list.ListItem) JobPanel(eu.esdihumboldt.hale.server.webapp.components.JobPanel) File(java.io.File)

Example 7 with LoadableDetachableModel

use of org.apache.wicket.model.LoadableDetachableModel in project wicket by apache.

the class PaletteTest method choicesModelAccountingForSelected.

/**
 * WICKET-4231 palette with choicesModel accounting for currently selected
 */
@Test
public void choicesModelAccountingForSelected() {
    final List<String> list = new ArrayList<>(Arrays.asList("D"));
    IModel<List<String>> selected = new ListModel<>(list);
    IModel<List<String>> all = new LoadableDetachableModel<List<String>>() {

        @Override
        protected List<String> load() {
            // normally coming from DB
            List<String> fromDB = Arrays.asList("A", "B", "C");
            List<String> result = new ArrayList<>();
            result.addAll(fromDB);
            // include already selected
            result.addAll(list);
            return result;
        }
    };
    PaletteTestPage testPage = new PaletteTestPage(selected, all);
    tester.startPage(testPage);
    FormTester formTester = tester.newFormTester(testPage.form.getId());
    formTester.submit();
    Collection<String> collection = testPage.palette.getModelCollection();
    assertEquals(1, collection.size());
    assertEquals("D", collection.iterator().next());
}
Also used : ListModel(org.apache.wicket.model.util.ListModel) LoadableDetachableModel(org.apache.wicket.model.LoadableDetachableModel) ArrayList(java.util.ArrayList) FormTester(org.apache.wicket.util.tester.FormTester) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 8 with LoadableDetachableModel

use of org.apache.wicket.model.LoadableDetachableModel in project openmeetings by apache.

the class CalendarPanel method onInitialize.

@Override
protected void onInitialize() {
    final Form<Date> form = new Form<>("form");
    add(form);
    dialog = new AppointmentDialog("appointment", this, new CompoundPropertyModel<>(getDefault()));
    add(dialog);
    boolean isRtl = isRtl();
    Options options = new Options();
    options.set("isRTL", isRtl);
    options.set("header", isRtl ? "{left: 'agendaDay,agendaWeek,month', center: 'title', right: 'today nextYear,next,prev,prevYear'}" : "{left: 'prevYear,prev,next,nextYear today', center: 'title', right: 'month,agendaWeek,agendaDay'}");
    options.set("allDaySlot", false);
    options.set("axisFormat", Options.asString("H(:mm)"));
    options.set("defaultEventMinutes", 60);
    options.set("timeFormat", Options.asString("H(:mm)"));
    options.set("buttonText", new JSONObject().put("month", getString("801")).put("week", getString("800")).put("day", getString("799")).put("today", getString("1555")).toString());
    JSONArray monthes = new JSONArray();
    JSONArray shortMonthes = new JSONArray();
    JSONArray days = new JSONArray();
    JSONArray shortDays = new JSONArray();
    // first week day must be Sunday
    days.put(0, getString("466"));
    shortDays.put(0, getString("459"));
    for (int i = 0; i < 12; i++) {
        monthes.put(i, getString(String.valueOf(469 + i)));
        shortMonthes.put(i, getString(String.valueOf(1556 + i)));
        if (i + 1 < 7) {
            days.put(i + 1, getString(String.valueOf(460 + i)));
            shortDays.put(i + 1, getString(String.valueOf(453 + i)));
        }
    }
    options.set("monthNames", monthes.toString());
    options.set("monthNamesShort", shortMonthes.toString());
    options.set("dayNames", days.toString());
    options.set("dayNamesShort", shortDays.toString());
    options.set("firstDay", cfgDao.getInt(CONFIG_CALENDAR_FIRST_DAY, 0));
    calendar = new Calendar("calendar", new AppointmentModel(), options) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onInitialize() {
            super.onInitialize();
            add(new CalendarFunctionsBehavior(getMarkupId()));
        }

        @Override
        public boolean isSelectable() {
            return true;
        }

        @Override
        public boolean isDayClickEnabled() {
            return true;
        }

        @Override
        public boolean isEventClickEnabled() {
            return true;
        }

        @Override
        public boolean isEventDropEnabled() {
            return true;
        }

        @Override
        public boolean isEventResizeEnabled() {
            return true;
        }

        // no need to override onDayClick
        @Override
        public void onSelect(AjaxRequestTarget target, CalendarView view, LocalDateTime start, LocalDateTime end, boolean allDay) {
            Appointment a = getDefault();
            LocalDateTime s = start, e = end;
            if (CalendarView.month == view) {
                LocalDateTime now = ZonedDateTime.now(getZoneId()).toLocalDateTime();
                s = start.withHour(now.getHour()).withMinute(now.getMinute());
                e = s.plus(1, ChronoUnit.HOURS);
            }
            a.setStart(getDate(s));
            a.setEnd(getDate(e));
            dialog.setModelObjectWithAjaxTarget(a, target);
            dialog.open(target);
        }

        @Override
        public void onEventClick(AjaxRequestTarget target, CalendarView view, int eventId) {
            Appointment a = apptDao.get((long) eventId);
            dialog.setModelObjectWithAjaxTarget(a, target);
            dialog.open(target);
        }

        @Override
        public void onEventDrop(AjaxRequestTarget target, int eventId, long delta, boolean allDay) {
            Appointment a = apptDao.get((long) eventId);
            if (!AppointmentDialog.isOwner(a)) {
                return;
            }
            java.util.Calendar cal = WebSession.getCalendar();
            cal.setTime(a.getStart());
            cal.add(java.util.Calendar.MILLISECOND, (int) delta);
            a.setStart(cal.getTime());
            cal.setTime(a.getEnd());
            cal.add(java.util.Calendar.MILLISECOND, (int) delta);
            a.setEnd(cal.getTime());
            apptDao.update(a, getUserId());
            if (a.getCalendar() != null) {
                updatedeleteAppointment(target, CalendarDialog.DIALOG_TYPE.UPDATE_APPOINTMENT, a);
            }
        }

        @Override
        public void onEventResize(AjaxRequestTarget target, int eventId, long delta) {
            Appointment a = apptDao.get((long) eventId);
            if (!AppointmentDialog.isOwner(a)) {
                return;
            }
            java.util.Calendar cal = WebSession.getCalendar();
            cal.setTime(a.getEnd());
            cal.add(java.util.Calendar.MILLISECOND, (int) delta);
            a.setEnd(cal.getTime());
            apptDao.update(a, getUserId());
            if (a.getCalendar() != null) {
                updatedeleteAppointment(target, CalendarDialog.DIALOG_TYPE.UPDATE_APPOINTMENT, a);
            }
        }
    };
    form.add(calendar);
    populateGoogleCalendars();
    add(refreshTimer);
    add(syncTimer);
    calendarDialog = new CalendarDialog("calendarDialog", this, new CompoundPropertyModel<>(getDefaultCalendar()));
    add(calendarDialog);
    calendarListContainer.setOutputMarkupId(true);
    calendarListContainer.add(new ListView<OmCalendar>("items", new LoadableDetachableModel<List<OmCalendar>>() {

        private static final long serialVersionUID = 1L;

        @Override
        protected List<OmCalendar> load() {
            List<OmCalendar> cals = new ArrayList<>(apptManager.getCalendars(getUserId()));
            cals.addAll(apptManager.getGoogleCalendars(getUserId()));
            return cals;
        }
    }) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<OmCalendar> item) {
            item.setOutputMarkupId(true);
            final OmCalendar cal = item.getModelObject();
            item.add(new Button("item", new PropertyModel<String>(cal, "title")).add(new AjaxEventBehavior(EVT_CLICK) {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onEvent(AjaxRequestTarget target) {
                    calendarDialog.open(target, CalendarDialog.DIALOG_TYPE.UPDATE_CALENDAR, cal);
                    target.add(calendarDialog);
                }
            }));
        }
    });
    add(new Button("syncCalendarButton").add(new AjaxEventBehavior(EVT_CLICK) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onEvent(AjaxRequestTarget target) {
            syncCalendar(target);
        }
    }));
    add(new Button("submitCalendar").add(new AjaxEventBehavior(EVT_CLICK) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onEvent(AjaxRequestTarget target) {
            calendarDialog.open(target, CalendarDialog.DIALOG_TYPE.UPDATE_CALENDAR, getDefaultCalendar());
            target.add(calendarDialog);
        }
    }));
    add(calendarListContainer);
    super.onInitialize();
}
Also used : LocalDateTime(java.time.LocalDateTime) Appointment(org.apache.openmeetings.db.entity.calendar.Appointment) Options(com.googlecode.wicket.jquery.core.Options) Form(org.apache.wicket.markup.html.form.Form) ArrayList(java.util.ArrayList) Button(com.googlecode.wicket.jquery.ui.form.button.Button) OmCalendar(org.apache.openmeetings.db.entity.calendar.OmCalendar) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) CalendarView(com.googlecode.wicket.jquery.ui.calendar.CalendarView) AjaxEventBehavior(org.apache.wicket.ajax.AjaxEventBehavior) OmCalendar(org.apache.openmeetings.db.entity.calendar.OmCalendar) Calendar(com.googlecode.wicket.jquery.ui.calendar.Calendar) GoogleCalendar(com.googlecode.wicket.jquery.ui.calendar.EventSource.GoogleCalendar) JSONArray(com.github.openjson.JSONArray) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) PropertyModel(org.apache.wicket.model.PropertyModel) Date(java.util.Date) CalendarWebHelper.getDate(org.apache.openmeetings.web.util.CalendarWebHelper.getDate) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) JSONObject(com.github.openjson.JSONObject) LoadableDetachableModel(org.apache.wicket.model.LoadableDetachableModel)

Aggregations

LoadableDetachableModel (org.apache.wicket.model.LoadableDetachableModel)8 ArrayList (java.util.ArrayList)5 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)2 User (de.tudarmstadt.ukp.clarin.webanno.security.model.User)2 DecoratedObject (de.tudarmstadt.ukp.clarin.webanno.support.wicket.DecoratedObject)2 List (java.util.List)2 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)2 ListItem (org.apache.wicket.markup.html.list.ListItem)2 ListView (org.apache.wicket.markup.html.list.ListView)2 JSONArray (com.github.openjson.JSONArray)1 JSONObject (com.github.openjson.JSONObject)1 Options (com.googlecode.wicket.jquery.core.Options)1 Calendar (com.googlecode.wicket.jquery.ui.calendar.Calendar)1 CalendarView (com.googlecode.wicket.jquery.ui.calendar.CalendarView)1 GoogleCalendar (com.googlecode.wicket.jquery.ui.calendar.EventSource.GoogleCalendar)1 Button (com.googlecode.wicket.jquery.ui.form.button.Button)1 TransformationWorkspace (eu.esdihumboldt.hale.common.headless.transform.TransformationWorkspace)1 JobPanel (eu.esdihumboldt.hale.server.webapp.components.JobPanel)1 Activator (eu.esdihumboldt.hale.server.webapp.war.internal.Activator)1