You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by st...@apache.org on 2014/06/03 14:49:16 UTC
svn commit: r1599518 - in
/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views:
DateTimeCellEditor.java DateTimeEditor.java DateTimeSupport.java
JcrEditingSupport.java PropertyTypeSupport.java
Author: stefanegli
Date: Tue Jun 3 12:49:15 2014
New Revision: 1599518
URL: http://svn.apache.org/r1599518
Log:
SLING-3630 : Date/Time CellEditor added
Added:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/DateTimeCellEditor.java (with props)
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/DateTimeEditor.java (with props)
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/DateTimeSupport.java (with props)
Modified:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/JcrEditingSupport.java
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/PropertyTypeSupport.java
Added: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/DateTimeCellEditor.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/DateTimeCellEditor.java?rev=1599518&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/DateTimeCellEditor.java (added)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/DateTimeCellEditor.java Tue Jun 3 12:49:15 2014
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.ui.views;
+
+import org.apache.sling.ide.eclipse.ui.nav.model.JcrNode;
+import org.apache.sling.ide.eclipse.ui.nav.model.JcrProperty;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.viewers.DialogCellEditor;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+public class DateTimeCellEditor extends DialogCellEditor {
+
+ private final JcrNode node;
+ private final String propertyName;
+
+ public DateTimeCellEditor(Composite parent, JcrNode node, String propertyName) {
+ super(parent);
+ if (node==null) {
+ throw new IllegalArgumentException("node must not be null");
+ }
+ if (propertyName==null || propertyName.length()==0) {
+ throw new IllegalArgumentException("propertyName must not be null or empty");
+ }
+ this.node = node;
+ this.propertyName = propertyName;
+ }
+
+ @Override
+ protected Object openDialogBox(Control cellEditorWindow) {
+ final JcrProperty property = node.getProperty(propertyName);
+ final DateTimeEditor dtEditor = new DateTimeEditor(cellEditorWindow.getShell(), property);
+ if (dtEditor.open() == IStatus.OK) {
+ return dtEditor.getDate();
+ } else {
+ return null;
+ }
+ }
+
+}
Propchange: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/DateTimeCellEditor.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/DateTimeEditor.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/DateTimeEditor.java?rev=1599518&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/DateTimeEditor.java (added)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/DateTimeEditor.java Tue Jun 3 12:49:15 2014
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.ui.views;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+import javax.xml.bind.DatatypeConverter;
+
+import org.apache.sling.ide.eclipse.ui.nav.model.JcrProperty;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.DateTime;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+
+public class DateTimeEditor extends Dialog {
+
+ private final JcrProperty property;
+ private TableViewer viewer;
+ private Label result;
+ private DateTime calendar;
+ private DateTime time;
+ private String dateAsString;
+ private Calendar c;
+
+ protected DateTimeEditor(Shell parentShell, JcrProperty property) {
+ super(parentShell);
+ this.property = property;
+ }
+
+ @Override
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText("Modify date/time property");
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+
+ GridData parentLayoutData = new GridData(GridData.FILL_BOTH);
+ parentLayoutData.widthHint = 280;
+ parentLayoutData.heightHint = 280;
+ composite.setLayoutData(parentLayoutData);
+ GridLayout parentLayout = (GridLayout) composite.getLayout();
+ parentLayout.numColumns = 2;
+
+ Label label = new Label(composite, SWT.WRAP);
+ label.setText("Modify property "+property.getName()+":");
+ GridData data = new GridData(GridData.GRAB_HORIZONTAL
+ | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL
+ | GridData.VERTICAL_ALIGN_CENTER);
+ data.horizontalSpan = 2;
+ data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
+ label.setLayoutData(data);
+ label.setFont(parent.getFont());
+
+ Label hline = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
+ GridData layoutData = new GridData(GridData.FILL_HORIZONTAL);
+ layoutData.horizontalSpan = 2;
+ hline.setLayoutData(layoutData);
+
+ Label dateLabel = new Label(composite, SWT.WRAP);
+ dateLabel.setText("Date:");
+ layoutData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
+ layoutData.widthHint = 80;
+ dateLabel.setLayoutData(layoutData);
+ dateLabel.setFont(parent.getFont());
+
+ calendar = new DateTime(composite, SWT.CALENDAR);
+ layoutData = new GridData(GridData.FILL_VERTICAL | GridData.HORIZONTAL_ALIGN_BEGINNING);
+ layoutData.horizontalSpan = 1;
+ calendar.setLayoutData(layoutData);
+ calendar.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ updateSelection();
+ }
+ });
+
+ Label timeLabel = new Label(composite, SWT.WRAP);
+ timeLabel.setText("Time:");
+ layoutData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
+ layoutData.widthHint = 80;
+ timeLabel.setLayoutData(layoutData);
+ timeLabel.setFont(parent.getFont());
+
+ time = new DateTime(composite, SWT.TIME);
+ layoutData = new GridData(GridData.FILL_VERTICAL | GridData.HORIZONTAL_ALIGN_BEGINNING);
+ layoutData.horizontalSpan = 1;
+ time.setLayoutData(layoutData);
+ time.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ updateSelection();
+ }
+ });
+
+ hline = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
+ layoutData = new GridData(GridData.FILL_HORIZONTAL);
+ layoutData.horizontalSpan = 2;
+ hline.setLayoutData(layoutData);
+
+ result = new Label(composite, SWT.WRAP);
+ result.setText("Foo");
+ data = new GridData(GridData.GRAB_HORIZONTAL
+ | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL
+ | GridData.VERTICAL_ALIGN_CENTER);
+ data.horizontalSpan = 2;
+ result.setLayoutData(data);
+ result.setFont(parent.getFont());
+
+ // initialize value
+ dateAsString = property.getValueAsString();
+ c = DateTimeSupport.parseAsCalendar(dateAsString);
+ calendar.setDate(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
+ time.setTime(c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), c.get(Calendar.SECOND));
+
+ updateSelection();
+ return composite;
+ }
+
+ protected void updateSelection() {
+ int day = calendar.getDay();
+ int month = calendar.getMonth();
+ int year = calendar.getYear();
+ int hours = time.getHours();
+ int minutes = time.getMinutes();
+ int seconds = time.getSeconds();
+ c = new GregorianCalendar(year, month, day, hours, minutes, seconds);
+ dateAsString = DateTimeSupport.print(c);
+ result.setText(dateAsString);
+ }
+
+ @Override
+ protected void okPressed() {
+ super.okPressed();
+ }
+
+ public Date getDate() {
+ return c.getTime();
+ }
+}
Propchange: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/DateTimeEditor.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/DateTimeSupport.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/DateTimeSupport.java?rev=1599518&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/DateTimeSupport.java (added)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/DateTimeSupport.java Tue Jun 3 12:49:15 2014
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.ui.views;
+
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+import javax.xml.bind.DatatypeConverter;
+
+public class DateTimeSupport {
+
+ public static Date parseAsDate(String vaultDateTime) {
+ return parseAsCalendar(vaultDateTime).getTime();
+ }
+
+ public static Calendar parseAsCalendar(String vaultDateTime) {
+ final Calendar result = DatatypeConverter.parseDateTime(vaultDateTime);
+ return result;
+ }
+
+ public static String print(Date date) {
+ Calendar c = Calendar.getInstance();
+ c.setTime(date);
+ return print(c);
+ }
+
+ public static String print(Calendar c) {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
+ String result = sdf.format(c.getTime());
+ SimpleDateFormat timezone = new SimpleDateFormat("Z");
+ String timezoneStr = timezone.format(c.getTime());
+ //make it ISO_8601 conform
+ timezoneStr = timezoneStr.substring(0, timezoneStr.length()-2) + ":" + timezoneStr.substring(timezoneStr.length()-2);
+ return result+timezoneStr;
+ }
+}
Propchange: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/DateTimeSupport.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/JcrEditingSupport.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/JcrEditingSupport.java?rev=1599518&r1=1599517&r2=1599518&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/JcrEditingSupport.java (original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/JcrEditingSupport.java Tue Jun 3 12:49:15 2014
@@ -279,9 +279,9 @@ public class JcrEditingSupport extends E
// then launch the MVPEditor instead of returning an editor here
return new MVNCellEditor(tableViewer.getTable(), getNode(), field.getPropertyName());
}
-// if (getNode().getPropertyType(field.getPropertyName())==PropertyType.DATE) {
-// return new DateTimeCellEditor(tableViewer.getTable(), getNode(), field.getPropertyName());
-// }
+ if (getNode().getPropertyType(field.getPropertyName())==PropertyType.DATE) {
+ return new DateTimeCellEditor(tableViewer.getTable(), getNode(), field.getPropertyName());
+ }
CellEditor editor;
if (field.getPropertyName().equals("jcr:primaryType")) {
editor = new TextCellEditor(tableViewer.getTable()) {
Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/PropertyTypeSupport.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/PropertyTypeSupport.java?rev=1599518&r1=1599517&r2=1599518&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/PropertyTypeSupport.java (original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/views/PropertyTypeSupport.java Tue Jun 3 12:49:15 2014
@@ -17,6 +17,8 @@
package org.apache.sling.ide.eclipse.ui.views;
import java.net.URI;
+import java.util.Calendar;
+import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
@@ -103,10 +105,14 @@ public class PropertyTypeSupport {
return "";
}
case PropertyType.DATE: {
- //TODO: double check
- if (value instanceof GregorianCalendar) {
+ if (value instanceof Date) {
+ Date date = (Date)value;
+ Calendar c = Calendar.getInstance();
+ c.setTime(date);
+ return DateTimeSupport.print(c);
+ } else if (value instanceof GregorianCalendar) {
GregorianCalendar date = (GregorianCalendar)value;
- return date.toString();
+ return DateTimeSupport.print(date);
} else {
return String.valueOf(value);
}