Skip to content

Commit

Permalink
Issue 355
Browse files Browse the repository at this point in the history
The toolbar of the date picker in CDateTime cannot be styled using
Eclipse CSS #355
  • Loading branch information
lcaron authored and LaurentCaronAkuiteo committed Feb 1, 2022
1 parent 118e1e0 commit b62955f
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@
<property-name name="cdt-button-hover-background-color"> </property-name>
<property-name name="cdt-button-selected-border-color"> </property-name>
<property-name name="cdt-button-selected-background-color"> </property-name>

<property-name name="cdt-ok-color"> </property-name>
<property-name name="cdt-cancel-color"> </property-name>
<property-name name="cdt-clear-color"> </property-name>
<property-name name="cdt-clear-color"> </property-name>
<property-name name="cdt-clear-font-style"> </property-name>
<property-name name="cdt-clear-font-size"> </property-name>
<property-name name="cdt-clear-font-weight"> </property-name>
<property-name name="cdt-clear-font-family"> </property-name>
</handler>
</extension>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,36 @@ public boolean applyCSSProperty(final Object element, final String property, fin
final Color newColor = (Color) engine.convert(value, Color.class, cdt.getDisplay());
cdt.setButtonSelectedBackgroundColor(newColor);
}

// Ok, Cancel & clear buttons
if ("cdt-ok-color".equals(property)) {
final Color newColor = (Color) engine.convert(value, Color.class, cdt.getDisplay());
cdt.setOkButtonColor(newColor);
}
if ("cdt-cancel-color".equals(property)) {
final Color newColor = (Color) engine.convert(value, Color.class, cdt.getDisplay());
cdt.setCancelButtonColor(newColor);
}
if ("cdt-clear-color".equals(property)) {
final Color newColor = (Color) engine.convert(value, Color.class, cdt.getDisplay());
cdt.setClearButtonForegroundColor(newColor);
}

if ("cdt-clear-font".equals(property)) {
applyCSSPropertyFont(cdt, value, true);
}
if ("cdt-clear-font-style".equals(property)) {
applyCSSPropertyStyle(cdt, value, true);
}
if ("cdt-clear-font-size".equals(property)) {
applyCSSPropertySize(cdt, value, true);
}
if ("cdt-clear-font-weight".equals(property)) {
applyCSSPropertyWeight(cdt, value, true);
}
if ("cdt-clear-font-family".equals(property)) {
applyCSSPropertyFamily(cdt, value, true);
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ CDateTime#four,CDateTime#five,CDateTime#six {
cdt-button-selected-background-color: red;
}

CDateTime#okcancelclear {
cdt-ok-color: red;
cdt-cancel-color: green;
cdt-clear-color: cyan;
cdt-clear-font: Verdana 11px;
}

CDateTime#big_one {
cdt-picker-font: Verdana 10px;
cdt-picker-color: magenta;
Expand All @@ -75,3 +82,4 @@ CDateTime#big_one {
CDateTime#big_two {
cdt-background-color: darkred;
}

Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ public void createComposite(final Composite parent) {
year.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
year.setData(CSS_ID, "six");

// Last
label = new Label(group, SWT.NONE);
label.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
label.setText("Date widget with pop-up shell\n(custom ok/cancel/clear button");

final CDateTime cdt6 = new CDateTime(group, CDT.BORDER | CDT.COMPACT | CDT.DROP_DOWN | CDT.DATE_LONG | CDT.TIME_MEDIUM);
final GridData gd6 = new GridData(SWT.BEGINNING, SWT.CENTER, true, false);
gd6.widthHint = 150;
cdt6.setLayoutData(gd6);
cdt6.setSelection(new Date());
cdt6.setData(CSS_ID, "okcancelclear");

}

@Focus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,10 @@ private static int convertStyle(int style) {
break;
case SWT.MouseWheel:
Control focusedControl = getDisplay().getFocusControl();
if (getTextWidget() != null && getTextWidget().getControl() != focusedControl) {
// Do not handle mousewheel events if the widget does not have focus
if (getTextWidget() != null
&& getTextWidget().getControl() != focusedControl) {
// Do not handle mousewheel events if the widget does not have
// focus
break;
}
if (event.count > 0) {
Expand Down Expand Up @@ -371,7 +373,11 @@ private static int convertStyle(int style) {

Color pickerActiveDayColor, pickerInactiveDayColor, pickerTodayColor;
Color pickerMinutesColor, pickerMinutesBackgroundColor;


Color okButtonColor, cancelButtonColor, clearButtonForegroundColor;
Font clearButtonFont;
private VButton okButton, clearButton, cancelButton;

/**
* Constructs a new instance of this class given its parent and a style
* value describing its behavior and appearance. The current date and the
Expand Down Expand Up @@ -515,7 +521,7 @@ private void createPicker() {
if (pickerFont != null) {
pickerPanel.setFont(pickerFont);
}

if (isDate) {
DatePicker dp = new DatePicker(this);
dp.setScrollable(scrollable);
Expand Down Expand Up @@ -552,47 +558,50 @@ private void createPickerToolbar(VPanel parent) {
tb.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false));
tb.setData(CDT.PickerPart, PickerPart.Toolbar);

VButton b = new VButton(tb, SWT.OK | SWT.NO_FOCUS);
b.setData(CDT.PickerPart, PickerPart.OkButton);
b.setToolTipText(Resources.getString("accept.text", locale)); //$NON-NLS-1$
b.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
b.addListener(SWT.Selection, event -> setOpen(false));
b.setHoverBackgroundColor(buttonHoverBackgroundColor);
b.setHoverBorderColor(buttonHoverBorderColor);
b.setSelectedBackgroundColor(buttonSelectedBackgroundColor);
b.setSelectedBorderColor(buttonSelectedBorderColor);

b = new VButton(tb, SWT.CANCEL | SWT.NO_FOCUS);
b.setData(CDT.PickerPart, PickerPart.CancelButton);
b.setToolTipText(Resources.getString("cancel.text", locale)); //$NON-NLS-1$
b.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
b.addListener(SWT.Selection, event -> {
okButton = new VButton(tb, SWT.OK | SWT.NO_FOCUS);
okButton.setData(CDT.PickerPart, PickerPart.OkButton);
okButton.setToolTipText(Resources.getString("accept.text", locale)); //$NON-NLS-1$
okButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
okButton.addListener(SWT.Selection, event -> setOpen(false));
okButton.setHoverBackgroundColor(buttonHoverBackgroundColor);
okButton.setHoverBorderColor(buttonHoverBorderColor);
okButton.setSelectedBackgroundColor(buttonSelectedBackgroundColor);
okButton.setSelectedBorderColor(buttonSelectedBorderColor);
okButton.setForeground(okButtonColor);

cancelButton = new VButton(tb, SWT.CANCEL | SWT.NO_FOCUS);
cancelButton.setData(CDT.PickerPart, PickerPart.CancelButton);
cancelButton.setToolTipText(Resources.getString("cancel.text", locale)); //$NON-NLS-1$
cancelButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
cancelButton.addListener(SWT.Selection, event -> {
setSelection(cancelDate);
fireSelectionChanged();
setOpen(false);
});
b.setHoverBackgroundColor(buttonHoverBackgroundColor);
b.setHoverBorderColor(buttonHoverBorderColor);
b.setSelectedBackgroundColor(buttonSelectedBackgroundColor);
b.setSelectedBorderColor(buttonSelectedBorderColor);

b = new VButton(tb, SWT.NO_FOCUS);
b.setData(CDT.PickerPart, PickerPart.ClearButton);
b.setText(Resources.getString("clear.text", locale)); //$NON-NLS-1$
b.setToolTipText(Resources.getString("clear.text", locale)); //$NON-NLS-1$
b.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
b.addListener(SWT.Selection, event -> {
cancelButton.setHoverBackgroundColor(buttonHoverBackgroundColor);
cancelButton.setHoverBorderColor(buttonHoverBorderColor);
cancelButton.setSelectedBackgroundColor(buttonSelectedBackgroundColor);
cancelButton.setSelectedBorderColor(buttonSelectedBorderColor);
cancelButton.setForeground(cancelButtonColor);

clearButton = new VButton(tb, SWT.NO_FOCUS);
clearButton.setData(CDT.PickerPart, PickerPart.ClearButton);
clearButton.setText(Resources.getString("clear.text", locale)); //$NON-NLS-1$
clearButton.setToolTipText(Resources.getString("clear.text", locale)); //$NON-NLS-1$
clearButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
clearButton.addListener(SWT.Selection, event -> {
setOpen(false);
setSelection(null);
fireSelectionChanged();
});
b.setForeground(parent.getForeground());
b.setFont(parent.getFont());
b.setHoverBackgroundColor(buttonHoverBackgroundColor);
b.setHoverBorderColor(buttonHoverBorderColor);
b.setSelectedBackgroundColor(buttonSelectedBackgroundColor);
b.setSelectedBorderColor(buttonSelectedBorderColor);

clearButton.setForeground(clearButtonForegroundColor!=null?clearButtonForegroundColor:parent.getForeground());
clearButton.setFont(clearButtonFont!=null?clearButtonFont:parent.getFont());
clearButton.setHoverBackgroundColor(buttonHoverBackgroundColor);
clearButton.setHoverBorderColor(buttonHoverBorderColor);
clearButton.setSelectedBackgroundColor(buttonSelectedBackgroundColor);
clearButton.setSelectedBorderColor(buttonSelectedBorderColor);


VLabel sep = new VLabel(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
sep.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
}
Expand Down Expand Up @@ -1389,8 +1398,7 @@ private void init(int style) {
}
spinner = VNative.create(Spinner.class, panel, sStyle);
if (win32) {
spinner.setBackground(
text.getControl().getBackground());
spinner.setBackground(text.getControl().getBackground());
}
spinner.getControl().setMinimum(0);
spinner.getControl().setMaximum(50);
Expand Down Expand Up @@ -2253,8 +2261,6 @@ public void setBackground(Color color) {
}
}



public void setForeground(Color color) {
super.setForeground(color);
if (picker != null) {
Expand Down Expand Up @@ -2285,7 +2291,7 @@ public void setButtonHoverBorderColor(Color color) {
picker.updateColorsAndFont();
}
}

/**
* @param color
* @since 1.5
Expand Down Expand Up @@ -2329,7 +2335,7 @@ public void setPickerForegroundColor(Color pickerForegroundColor) {
if (pickerForegroundColor != null && pickerPanel != null) {
pickerPanel.setForeground(pickerForegroundColor);
}
if (picker != null && pickerPanel != null&& pickerPanel != null) {
if (picker != null && pickerPanel != null && pickerPanel != null) {
picker.updateColorsAndFont();
}
}
Expand Down Expand Up @@ -2515,13 +2521,82 @@ public Color getPickerMinutesBackgroundColor() {
* @param pickerMinutesBackgroundColor
* @since 1.5
*/
public void setPickerMinutesBackgroundColor(Color pickerMinutesBackgroundColor) {
public void setPickerMinutesBackgroundColor(
Color pickerMinutesBackgroundColor) {
checkWidget();
this.pickerMinutesBackgroundColor = pickerMinutesBackgroundColor;
if (picker != null) {
picker.updateColorsAndFont();
}
}


/**
* @return the foreground color of the "Ok" button
*/
public Color getOkButtonColor() {
checkWidget();
return okButtonColor;
}

/**
* @param okButtonColor the new foreground color of the "ok" button
*/
public void setOkButtonColor(Color okButtonColor) {
checkWidget();
this.okButtonColor = okButtonColor;
if (okButton != null) okButton.setForeground(okButtonColor);
}

/**
* @return the foreground color of the "Cancel" button
*/
public Color getCancelButtonColor() {
checkWidget();
return cancelButtonColor;
}

/**
* @param cancelButtonColor the new foreground color of the "cancel" button
*/
public void setCancelButtonColor(Color cancelButtonColor) {
checkWidget();
this.cancelButtonColor = cancelButtonColor;
if (cancelButton != null) cancelButton.setForeground(cancelButtonColor);
}

/**
* @return the foreground color of the "clear" button
*/
public Color getClearButtonForegroundColor() {
checkWidget();
return clearButtonForegroundColor;
}

/**
* @param clearButtonForegroundColor the new foreground color of the "clear" button
*/
public void setClearButtonForegroundColor(
Color clearButtonForegroundColor) {
checkWidget();
this.clearButtonForegroundColor = clearButtonForegroundColor;
if (clearButton != null) clearButton.setForeground(clearButtonForegroundColor);
}

/**
* @return the font of the "clear" button
*/
public Font getClearButtonFont() {
checkWidget();
return clearButtonFont;
}

/**
* @param clearButtonFont the new font of the "clear" button
*/
public void setClearButtonFont(Font clearButtonFont) {
checkWidget();
this.clearButtonFont = clearButtonFont;
if (clearButton != null) clearButton.setFont(clearButtonFont);
}

}
2 changes: 1 addition & 1 deletion widgets/cwt/org.eclipse.nebula.cwt/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ Export-Package: org.eclipse.nebula.cwt.animation,
org.eclipse.nebula.cwt.svg,
org.eclipse.nebula.cwt.v
Automatic-Module-Name: org.eclipse.nebula.cwt
Require-Bundle: org.eclipse.swt;bundle-version="3.1.0"
Require-Bundle: org.eclipse.swt
Loading

0 comments on commit b62955f

Please sign in to comment.