@Override protected void setEditedValue(URI element, Object value) throws Exception { IEpisode oldEpisode = LocatorService.INSTANCE.resolve(element, IEpisode.class, null).get(); if (oldEpisode != null) { try { ICodeService codeService = (ICodeService) PlatformUI.getWorkbench().getService(ICodeService.class); IEpisode newEpisode = null; if (this.field == Field.NAME) { String newCaption = (String) value; newEpisode = oldEpisode.changeCaption(newCaption); } else if (this.field == Field.STARTDATE) { TimeZoneDate newStartDate = (TimeZoneDate) value; TimeZoneDateRange range = new TimeZoneDateRange(newStartDate, oldEpisode.getDateRange().getEndDate()); newEpisode = oldEpisode.changeRange(range); } else if (this.field == Field.ENDDATE) { TimeZoneDate newEndDate = (TimeZoneDate) value; TimeZoneDateRange range = new TimeZoneDateRange(oldEpisode.getDateRange().getStartDate(), newEndDate); newEpisode = oldEpisode.changeRange(range); } if (newEpisode == null) { throw new NullPointerException("Invalid field"); } codeService.replaceEpisodeAndSave(oldEpisode, newEpisode); ViewerUtils.refresh(this.getViewer(), true); } catch (Exception e) { LOGGER.error("Could not save changed " + IEpisode.class.getSimpleName() + " " + value, e); } } }
@Override protected CellEditor getCellEditor(URI element, Composite composite) throws Exception { IEpisode episode = LocatorService.INSTANCE.resolve(element, IEpisode.class, null).get(); if (episode != null) { if (this.field == Field.NAME) { return new TextCellEditor(composite); } else { return new DateTimeCellEditor(composite); } } return null; }
@Override protected Object getInitValue(URI element) throws Exception { IEpisode episode = LocatorService.INSTANCE.resolve(element, IEpisode.class, null).get(); if (episode != null) { if (this.field == Field.NAME) { return episode.getCaption(); } else if (this.field == Field.STARTDATE) { return episode.getDateRange().getStartDate(); } else if (this.field == Field.ENDDATE) { return episode.getDateRange().getEndDate(); } } return null; }