001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.ui.apps.publishqueue;
029
030import org.opencms.main.CmsException;
031import org.opencms.main.CmsLog;
032import org.opencms.main.OpenCms;
033import org.opencms.publish.CmsPublishJobBase;
034import org.opencms.publish.CmsPublishJobEnqueued;
035import org.opencms.publish.CmsPublishJobFinished;
036import org.opencms.publish.CmsPublishJobRunning;
037import org.opencms.security.CmsRole;
038import org.opencms.ui.A_CmsUI;
039import org.opencms.ui.CmsCssIcon;
040import org.opencms.ui.CmsVaadinUtils;
041import org.opencms.ui.apps.CmsAppWorkplaceUi;
042import org.opencms.ui.apps.Messages;
043import org.opencms.ui.components.CmsBasicDialog;
044import org.opencms.ui.components.CmsBasicDialog.DialogWidth;
045import org.opencms.ui.components.OpenCmsTheme;
046import org.opencms.ui.contextmenu.CmsContextMenu;
047import org.opencms.ui.contextmenu.CmsMenuItemVisibilityMode;
048import org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry;
049import org.opencms.util.CmsStringUtil;
050import org.opencms.util.CmsUUID;
051
052import java.util.ArrayList;
053import java.util.Collections;
054import java.util.Date;
055import java.util.HashMap;
056import java.util.List;
057import java.util.Locale;
058import java.util.Map;
059import java.util.Set;
060
061import org.apache.commons.logging.Log;
062
063import com.vaadin.event.MouseEvents;
064import com.vaadin.server.Resource;
065import com.vaadin.shared.MouseEventDetails.MouseButton;
066import com.vaadin.ui.Button;
067import com.vaadin.ui.Window;
068import com.vaadin.ui.themes.ValoTheme;
069import com.vaadin.v7.data.Item;
070import com.vaadin.v7.data.util.IndexedContainer;
071import com.vaadin.v7.data.util.filter.Or;
072import com.vaadin.v7.data.util.filter.SimpleStringFilter;
073import com.vaadin.v7.event.ItemClickEvent;
074import com.vaadin.v7.event.ItemClickEvent.ItemClickListener;
075import com.vaadin.v7.ui.Table;
076
077/**
078 * Class for Vaadin Table showing history queue elements.<p>
079 */
080public class CmsQueuedTable extends Table {
081
082    /**
083     *Menu entry for showing report.<p>
084     */
085    class EntryReport implements I_CmsSimpleContextMenuEntry<Set<String>>, I_CmsSimpleContextMenuEntry.I_HasCssStyles {
086
087        /**
088         * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#executeAction(java.lang.Object)
089         */
090        public void executeAction(Set<String> data) {
091
092            showReportDialog(data.iterator().next());
093        }
094
095        /**
096         * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry.I_HasCssStyles#getStyles()
097         */
098        public String getStyles() {
099
100            return ValoTheme.LABEL_BOLD;
101        }
102
103        /**
104         * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getTitle(java.util.Locale)
105         */
106        public String getTitle(Locale locale) {
107
108            return CmsVaadinUtils.getMessageText(Messages.GUI_PQUEUE_REPORT_0);
109        }
110
111        /**
112         * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getVisibility(java.lang.Object)
113         */
114        public CmsMenuItemVisibilityMode getVisibility(Set<String> data) {
115
116            return (data != null) && (data.size() == 1)
117            ? CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE
118            : CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE;
119        }
120
121    }
122
123    /**
124     * Menu entry for showing resources.<p>
125     */
126    class EntryResources implements I_CmsSimpleContextMenuEntry<Set<String>> {
127
128        /**
129         * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#executeAction(java.lang.Object)
130         */
131        public void executeAction(Set<String> data) {
132
133            showResourceDialog(data.iterator().next());
134
135        }
136
137        /**
138         * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getTitle(java.util.Locale)
139         */
140        public String getTitle(Locale locale) {
141
142            return CmsVaadinUtils.getMessageText(Messages.GUI_PQUEUE_RESOURCES_0);
143        }
144
145        /**
146         * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getVisibility(java.lang.Object)
147         */
148        public CmsMenuItemVisibilityMode getVisibility(Set<String> data) {
149
150            return (data != null) && (data.size() == 1)
151            ? CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE
152            : CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE;
153        }
154    }
155
156    /**
157     * Menu entry for option to abort publish job.<p>
158     */
159    class EntryStop implements I_CmsSimpleContextMenuEntry<Set<String>>, I_CmsSimpleContextMenuEntry.I_HasCssStyles {
160
161        /**
162         * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#executeAction(java.lang.Object)
163         */
164        public void executeAction(Set<String> data) {
165
166            String jobid = data.iterator().next();
167            CmsPublishJobBase job = OpenCms.getPublishManager().getJobByPublishHistoryId(new CmsUUID(jobid));
168            if (job instanceof CmsPublishJobEnqueued) {
169                try {
170                    OpenCms.getPublishManager().abortPublishJob(
171                        A_CmsUI.getCmsObject(),
172                        (CmsPublishJobEnqueued)job,
173                        true);
174                    CmsAppWorkplaceUi.get().reload();
175                } catch (CmsException e) {
176                    LOG.error("Error on aborting publish job.", e);
177                }
178            }
179        }
180
181        /**
182         * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry.I_HasCssStyles#getStyles()
183         */
184        public String getStyles() {
185
186            return ValoTheme.LABEL_BOLD;
187        }
188
189        /**
190         * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getTitle(java.util.Locale)
191         */
192        public String getTitle(Locale locale) {
193
194            return CmsVaadinUtils.getMessageText(Messages.GUI_PQUEUE_STOP_0);
195        }
196
197        /**
198         * @see org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry#getVisibility(java.lang.Object)
199         */
200        public CmsMenuItemVisibilityMode getVisibility(Set<String> data) {
201
202            return (data != null) && (data.size() == 1)
203            ? CmsMenuItemVisibilityMode.VISIBILITY_ACTIVE
204            : CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE;
205        }
206
207    }
208
209    /**Error status icon. */
210    public static final String ICON_ERROR = "apps/publishqueue/state_error.png";
211
212    /**Ok status icon. */
213    public static final String ICON_OK = "apps/publishqueue/state_ok.png";
214
215    /**Warning status icon. */
216    public static final String ICON_WARNINGS = "apps/publishqueue/state_warning.png";
217
218    /** list action id constant. */
219    public static final String LIST_ACTION_COUNT = "ac";
220
221    /** list action id constant. */
222    public static final String LIST_ACTION_END = "ae";
223
224    /** list action id constant. */
225    public static final String LIST_ACTION_PROJECT = "ap";
226
227    /** list action id constant. */
228    public static final String LIST_ACTION_START = "as";
229
230    /** list action id constant. */
231    public static final String LIST_ACTION_STATE_ERR = "ate";
232
233    /** list action id constant. */
234    public static final String LIST_ACTION_STATE_OK = "ato";
235
236    /** list action id constant. */
237    public static final String LIST_ACTION_VIEW = "av";
238
239    /** list id constant. */
240    public static final String LIST_ID = "lppq";
241
242    /** The logger for this class. */
243    static Log LOG = CmsLog.getLog(CmsQueuedTable.class.getName());
244
245    /**table column. */
246    private static final String PROP_FILESCOUNT = "files";
247
248    /**table column. */
249    private static final String PROP_ICON = "icon";
250
251    /**table column. */
252    private static final String PROP_PROJECT = "project";
253
254    /**resources column.*/
255    private static final String PROP_RESOURCES = "resources";
256
257    /**table column. */
258    private static final String PROP_START = "start";
259
260    /**table column. */
261    private static final String PROP_STATUS = "status";
262
263    /**table column. */
264    private static final String PROP_STATUS_LOCALE = "status-locale";
265
266    /**table column. */
267    private static final String PROP_STOP = "stop";
268
269    /**table column. */
270    private static final String PROP_USER = "user";
271
272    /**vaadin serial id. */
273    private static final long serialVersionUID = 7507300060974348158L;
274
275    /** Publish job state constant. */
276    private static final String STATE_ERROR = "error";
277
278    /** Publish job state constant. */
279    private static final String STATE_OK = "ok";
280
281    /** Publish job state constant. */
282    private static final String STATE_WARNING = "warning";
283
284    /** Publish job state constant. */
285    private static final String STATE_RUNNING = "running";
286
287    /** Publish job state constant. */
288    private static final String STATE_ENQUEUE = "queue";
289
290    /** Publish job state constant. */
291    private static final Map<String, String> STATUS_MESSAGES = getStatusMap();
292
293    /**Container. */
294    IndexedContainer m_container;
295
296    /**Instance of calling class.*/
297    CmsPublishQueue m_manager;
298
299    /** The context menu. */
300    CmsContextMenu m_menu;
301
302    /** The available menu entries. */
303    private List<I_CmsSimpleContextMenuEntry<Set<String>>> m_menuEntries;
304
305    /** The available menu entries. */
306    private List<I_CmsSimpleContextMenuEntry<Set<String>>> m_menuEntriesEnq;
307
308    /**
309     * Default constructor.<p>
310     *
311     * @param manager instance of calling class
312     */
313    public CmsQueuedTable(CmsPublishQueue manager) {
314
315        m_manager = manager;
316        setSizeFull();
317        setCaption(CmsVaadinUtils.getMessageText(Messages.GUI_PQUEUE_PQUEUE_HIST_0));
318
319        m_menu = new CmsContextMenu();
320        m_menu.setAsTableContextMenu(this);
321
322        m_container = new IndexedContainer();
323        m_container.addContainerProperty(PROP_ICON, Resource.class, new CmsCssIcon(OpenCmsTheme.ICON_PUBLISH));
324        m_container.addContainerProperty(PROP_STATUS, String.class, null);
325        m_container.addContainerProperty(PROP_STATUS_LOCALE, String.class, null);
326        m_container.addContainerProperty(PROP_PROJECT, String.class, "");
327        m_container.addContainerProperty(PROP_START, Date.class, null);
328        m_container.addContainerProperty(PROP_STOP, Date.class, null);
329        m_container.addContainerProperty(PROP_USER, String.class, "");
330        m_container.addContainerProperty(PROP_FILESCOUNT, Integer.class, Integer.valueOf(1));
331        m_container.addContainerProperty(PROP_RESOURCES, List.class, null);
332
333        setContainerDataSource(m_container);
334        //        setItemIconPropertyId(PROP_ICON);
335        //        setRowHeaderMode(RowHeaderMode.ICON_ONLY);
336        setColumnHeader(PROP_STATUS_LOCALE, "");
337        setColumnHeader(PROP_RESOURCES, CmsVaadinUtils.getMessageText(Messages.GUI_PQUEUE_RESOURCES_0));
338        setColumnHeader(PROP_PROJECT, CmsVaadinUtils.getMessageText(Messages.GUI_PQUEUE_PROJECT_0));
339        setColumnHeader(PROP_START, CmsVaadinUtils.getMessageText(Messages.GUI_PQUEUE_STARTDATE_0));
340        setColumnHeader(PROP_STOP, CmsVaadinUtils.getMessageText(Messages.GUI_PQUEUE_ENDDATE_0));
341        setColumnHeader(PROP_USER, CmsVaadinUtils.getMessageText(Messages.GUI_PQUEUE_USER_0));
342        setColumnHeader(PROP_FILESCOUNT, CmsVaadinUtils.getMessageText(Messages.GUI_PQUEUE_SIZE_0));
343
344        setVisibleColumns(
345            PROP_STATUS_LOCALE,
346            PROP_PROJECT,
347            PROP_START,
348            PROP_STOP,
349            PROP_USER,
350            PROP_RESOURCES,
351            PROP_FILESCOUNT);
352        setColumnWidth(PROP_START, 200);
353        setColumnWidth(PROP_STOP, 200);
354        setColumnWidth(PROP_RESOURCES, 550);
355
356        setItemIconPropertyId(PROP_ICON);
357        setRowHeaderMode(RowHeaderMode.ICON_ONLY);
358        setColumnWidth(null, 40);
359
360        setSelectable(true);
361
362        addItemClickListener(new ItemClickListener() {
363
364            /**vaadin serial id. */
365            private static final long serialVersionUID = -7394790444104979594L;
366
367            public void itemClick(ItemClickEvent event) {
368
369                onItemClick(event, event.getItemId(), event.getPropertyId());
370
371            }
372
373        });
374
375        setCellStyleGenerator(new CellStyleGenerator() {
376
377            private static final long serialVersionUID = 1L;
378
379            public String getStyle(Table source, Object itemId, Object propertyId) {
380
381                if (PROP_RESOURCES.equals(propertyId)) {
382                    return " " + OpenCmsTheme.HOVER_COLUMN;
383                }
384
385                if (PROP_PROJECT.equals(propertyId) & !(itemId instanceof CmsPublishJobEnqueued)) {
386                    return " " + OpenCmsTheme.HOVER_COLUMN;
387                }
388
389                if (PROP_STATUS_LOCALE.equals(propertyId)) {
390                    if (STATE_OK.equals(source.getItem(itemId).getItemProperty(PROP_STATUS).getValue())) {
391                        return OpenCmsTheme.TABLE_COLUMN_BOX_GREEN;
392                    }
393                    if (STATE_WARNING.equals(source.getItem(itemId).getItemProperty(PROP_STATUS).getValue())) {
394                        return OpenCmsTheme.TABLE_COLUMN_BOX_ORANGE;
395                    }
396                    if (STATE_ERROR.equals(source.getItem(itemId).getItemProperty(PROP_STATUS).getValue())) {
397                        return OpenCmsTheme.TABLE_COLUMN_BOX_RED;
398                    }
399                    if (STATE_RUNNING.equals(source.getItem(itemId).getItemProperty(PROP_STATUS).getValue())) {
400                        return OpenCmsTheme.TABLE_COLUMN_BOX_DARKGRAY;
401                    }
402                    if (STATE_ENQUEUE.equals(source.getItem(itemId).getItemProperty(PROP_STATUS).getValue())) {
403                        return OpenCmsTheme.TABLE_COLUMN_BOX_GRAY;
404                    }
405                }
406
407                return null;
408            }
409        });
410
411        addGeneratedColumn(PROP_RESOURCES, new CmsResourcesCellGenerator(50));
412        loadJobs();
413    }
414
415    /**
416     * Returns the status message map.<p>
417     *
418     * @return the status message map
419     */
420    private static Map<String, String> getStatusMap() {
421
422        Map<String, String> map = new HashMap<String, String>();
423        map.put(STATE_OK, Messages.GUI_PQUEUE_STATUS_OK_0);
424        map.put(STATE_WARNING, Messages.GUI_PQUEUE_STATUS_WARNING_0);
425        map.put(STATE_ERROR, Messages.GUI_PQUEUE_STATUS_ERROR_0);
426        map.put(STATE_RUNNING, Messages.GUI_PQUEUE_STATUS_RUNNING_0);
427        map.put(STATE_ENQUEUE, Messages.GUI_PQUEUE_STATUS_ENQUEUE_0);
428
429        return map;
430    }
431
432    /**
433     * Filters the table according to given search string.<p>
434     *
435     * @param search string to be looked for.
436     */
437    public void filterTable(String search) {
438
439        m_container.removeAllContainerFilters();
440        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(search)) {
441            m_container.addContainerFilter(
442                new Or(
443                    new SimpleStringFilter(PROP_USER, search, true, false),
444                    new SimpleStringFilter(PROP_RESOURCES, search, true, false),
445                    new SimpleStringFilter(PROP_PROJECT, search, true, false)));
446        }
447    }
448
449    /**
450     * Show report dialog.<p>
451     *
452     * @param jobid to show report for
453     */
454    protected void showReportDialog(String jobid) {
455
456        CmsPublishReport pReport = new CmsPublishReport(jobid);
457        final Window window = CmsBasicDialog.prepareWindow(DialogWidth.wide);
458        CmsBasicDialog dialog = new CmsBasicDialog();
459        dialog.addButton(
460            new Button(
461                CmsVaadinUtils.getMessageText(org.opencms.workplace.Messages.GUI_DIALOG_BUTTON_CLOSE_0),
462                new com.vaadin.ui.Button.ClickListener() {
463
464                    private static final long serialVersionUID = -4216949392648631634L;
465
466                    public void buttonClick(com.vaadin.ui.Button.ClickEvent event) {
467
468                        window.close();
469
470                    }
471                }),
472            true);
473        dialog.setContent(pReport);
474        window.setContent(dialog);
475        window.setCaption(pReport.getCaption());
476        A_CmsUI.get().addWindow(window);
477    }
478
479    /**
480     * Show resource dialog.<p>
481     *
482     * @param jobid to show resources for
483     */
484    protected void showResourceDialog(String jobid) {
485
486        CmsPublishResources pResources = new CmsPublishResources(jobid);
487        final Window window = CmsBasicDialog.prepareWindow(DialogWidth.wide);
488        CmsBasicDialog dialog = new CmsBasicDialog();
489        dialog.addButton(
490            new Button(
491                CmsVaadinUtils.getMessageText(org.opencms.workplace.Messages.GUI_DIALOG_BUTTON_CLOSE_0),
492                new com.vaadin.ui.Button.ClickListener() {
493
494                    private static final long serialVersionUID = -4216949392648631634L;
495
496                    public void buttonClick(com.vaadin.ui.Button.ClickEvent event) {
497
498                        window.close();
499
500                    }
501                }),
502            true);
503        dialog.setContent(pResources);
504        window.setContent(dialog);
505        window.setCaption(pResources.getCaption());
506        A_CmsUI.get().addWindow(window);
507    }
508
509    /**
510     * Returns the available menu entries.<p>
511     *
512     * @return the menu entries
513     */
514    List<I_CmsSimpleContextMenuEntry<Set<String>>> getMenuEntries() {
515
516        if (getValue() instanceof CmsPublishJobEnqueued) {
517            if (m_menuEntriesEnq == null) {
518                m_menuEntriesEnq = new ArrayList<I_CmsSimpleContextMenuEntry<Set<String>>>();
519                m_menuEntriesEnq.add(new EntryStop());
520                m_menuEntriesEnq.add(new EntryResources());
521            }
522            return m_menuEntriesEnq;
523        }
524
525        if (m_menuEntries == null) {
526            m_menuEntries = new ArrayList<I_CmsSimpleContextMenuEntry<Set<String>>>();
527            m_menuEntries.add(new EntryReport());
528            m_menuEntries.add(new EntryResources());
529        }
530        return m_menuEntries;
531    }
532
533    /**
534     * Handles the table item clicks, including clicks on images inside of a table item.<p>
535     *
536     * @param event the click event
537     * @param itemId of the clicked row
538     * @param propertyId column id
539     */
540    void onItemClick(MouseEvents.ClickEvent event, Object itemId, Object propertyId) {
541
542        setValue(null);
543        select(itemId);
544        if (event.getButton().equals(MouseButton.RIGHT) || (propertyId == null)) {
545            m_menu.setEntries(
546                getMenuEntries(),
547                Collections.singleton((((CmsPublishJobBase)getValue()).getPublishHistoryId()).getStringValue()));
548            m_menu.openForTable(event, itemId, propertyId, CmsQueuedTable.this);
549        } else if (event.getButton().equals(MouseButton.LEFT) && PROP_RESOURCES.equals(propertyId)) {
550            showResourceDialog(((CmsPublishJobBase)getValue()).getPublishHistoryId().getStringValue());
551        } else if (event.getButton().equals(MouseButton.LEFT) && PROP_PROJECT.equals(propertyId)) {
552            if (!(getValue() instanceof CmsPublishJobEnqueued)) {
553                showReportDialog((((CmsPublishJobBase)getValue()).getPublishHistoryId().getStringValue()));
554            }
555        }
556    }
557
558    /**
559     * Returns the state of the given publish job.<p>
560     *
561     * @param publishJob the publish job to get the state for
562     * @return the state of the given publish job
563     */
564    private String getState(CmsPublishJobFinished publishJob) {
565
566        byte[] reportBytes = null;
567        try {
568            reportBytes = OpenCms.getPublishManager().getReportContents(publishJob);
569        } catch (CmsException e) {
570            //Can't read report -> error
571            return STATE_ERROR;
572        }
573        if (reportBytes != null) {
574            String report = new String(reportBytes);
575            if (report.indexOf("<span class='err'>") > -1) {
576                //Report contains error span
577                return STATE_ERROR;
578
579            }
580            if (report.indexOf("<span class='warn'>") > -1) {
581                //Report contains warning span
582                return STATE_WARNING;
583
584            }
585        }
586        //no warning or error state detected -> ok
587        return STATE_OK;
588
589    }
590
591    /**
592     * Fills the table with finished publish jobs.<p>
593     */
594    private void loadJobs() {
595
596        List<CmsPublishJobFinished> publishJobs;
597        if (OpenCms.getRoleManager().hasRole(A_CmsUI.getCmsObject(), CmsRole.ROOT_ADMIN)) {
598            publishJobs = OpenCms.getPublishManager().getPublishHistory();
599        } else {
600            publishJobs = OpenCms.getPublishManager().getPublishHistory(
601                A_CmsUI.getCmsObject().getRequestContext().getCurrentUser());
602        }
603        for (CmsPublishJobFinished job : publishJobs) {
604            String state = getState(job);
605            Item item = m_container.addItem(job);
606            item.getItemProperty(PROP_PROJECT).setValue(job.getProjectName().replace("&#47;", "/")); //TODO better way for unescaping..
607            try {
608                item.getItemProperty(PROP_RESOURCES).setValue(
609                    A_CmsUI.getCmsObject().readPublishedResources(job.getPublishHistoryId()));
610            } catch (com.vaadin.v7.data.Property.ReadOnlyException | CmsException e) {
611                LOG.error("Error while read published Resources", e);
612            }
613            item.getItemProperty(PROP_STATUS).setValue(state);
614            item.getItemProperty(PROP_STATUS_LOCALE).setValue(
615                CmsVaadinUtils.getMessageText(STATUS_MESSAGES.get(state)));
616            item.getItemProperty(PROP_START).setValue(new Date(job.getStartTime()));
617            item.getItemProperty(PROP_STOP).setValue(new Date(job.getFinishTime()));
618            item.getItemProperty(PROP_USER).setValue(job.getUserName(A_CmsUI.getCmsObject()));
619            item.getItemProperty(PROP_FILESCOUNT).setValue(Integer.valueOf(job.getSize()));
620
621        }
622        //Sort table according to start time of jobs
623        m_container.sort(new String[] {PROP_START}, new boolean[] {false});
624
625        List<CmsPublishJobBase> jobs = new ArrayList<CmsPublishJobBase>();
626
627        //a) running jobs
628        if (OpenCms.getPublishManager().isRunning()) {
629            jobs.add(OpenCms.getPublishManager().getCurrentPublishJob());
630        }
631
632        //b) queued jobs
633        jobs.addAll(OpenCms.getPublishManager().getPublishQueue());
634        for (CmsPublishJobBase job : jobs) {
635            Item item = m_container.addItemAt(0, job);
636            item.getItemProperty(PROP_PROJECT).setValue(job.getProjectName().replace("&#47;", "/")); //TODO better way for unescaping..
637
638            //distinguish between running and enqueued jobs
639            if (job instanceof CmsPublishJobRunning) {
640                item.getItemProperty(PROP_RESOURCES).setValue(
641                    ((CmsPublishJobRunning)job).getPublishList().getAllResources());
642                item.getItemProperty(PROP_START).setValue(new Date(((CmsPublishJobRunning)job).getStartTime()));
643                item.getItemProperty(PROP_STATUS).setValue(STATE_RUNNING);
644                item.getItemProperty(PROP_STATUS_LOCALE).setValue(
645                    CmsVaadinUtils.getMessageText(STATUS_MESSAGES.get(STATE_RUNNING)));
646
647            } else {
648                item.getItemProperty(PROP_RESOURCES).setValue(
649                    ((CmsPublishJobEnqueued)job).getPublishList().getAllResources());
650                item.getItemProperty(PROP_STATUS).setValue(STATE_ENQUEUE);
651                item.getItemProperty(PROP_STATUS_LOCALE).setValue(
652                    CmsVaadinUtils.getMessageText(STATUS_MESSAGES.get(STATE_ENQUEUE)));
653
654            }
655            item.getItemProperty(PROP_USER).setValue(job.getUserName(A_CmsUI.getCmsObject()));
656            item.getItemProperty(PROP_FILESCOUNT).setValue(Integer.valueOf(job.getSize()));
657        }
658    }
659}