Skip to content
Snippets Groups Projects
Commit 661a23a4 authored by Florian Hölzl's avatar Florian Hölzl
Browse files

added hold checkbox in input/output view

refs 425
parent 674ba132
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,7 @@ Bundle-ActivationPolicy: lazy ...@@ -11,6 +11,7 @@ Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-Vendor: fortiss GmbH Bundle-Vendor: fortiss GmbH
Export-Package: org.fortiss.tooling.base.ui, Export-Package: org.fortiss.tooling.base.ui,
org.fortiss.tooling.base.ui.checkboxtablecell,
org.fortiss.tooling.base.ui.compose, org.fortiss.tooling.base.ui.compose,
org.fortiss.tooling.base.ui.contentprovider, org.fortiss.tooling.base.ui.contentprovider,
org.fortiss.tooling.base.ui.databinding, org.fortiss.tooling.base.ui.databinding,
......
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed 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.fortiss.tooling.base.ui.checkboxtablecell;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.CheckboxCellEditor;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TableViewer;
/**
* {@link EditingSupport} for checkbox cells.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: A39EE0F9184DD86FD5FC5D46A164976A
*/
public abstract class CheckBoxEditingSupport extends EditingSupport {
/**
* Stores the shared cell editor.
*/
private CellEditor cellEditor;
/** Constructor */
public CheckBoxEditingSupport(ColumnViewer viewer) {
super(viewer);
cellEditor = new CheckboxCellEditor(((TableViewer) viewer).getTable());
}
/** {@inheritDoc} */
@Override
protected boolean canEdit(Object element) {
return true;
}
/** {@inheritDoc} */
@Override
protected final CellEditor getCellEditor(Object element) {
return cellEditor;
}
/** {@inheritDoc} */
@Override
protected final Object getValue(Object element) {
return getBooleanValue(element);
}
/** Get the boolean value of this editor. */
protected abstract Boolean getBooleanValue(Object element);
/** {@inheritDoc} */
@Override
protected final void setValue(Object element, Object value) {
if (value instanceof Boolean) {
setBooleanValue(element, (Boolean) value);
getViewer().update(element, null);
}
}
/** Sets the boolean value to the model. */
protected abstract void setBooleanValue(Object element, Boolean value);
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed 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.fortiss.tooling.base.ui.checkboxtablecell;
import static org.eclipse.jface.resource.JFaceResources.getImageRegistry;
import static org.eclipse.swt.SWT.CHECK;
import static org.eclipse.swt.SWT.DEFAULT;
import static org.eclipse.swt.SWT.NO_TRIM;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Shell;
/**
* Checkbox label provider using checkbox button images as representation. This
* class supports checked and enabled state.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: BDA0B84E86A88AC31CFF2B2C1B367A98
*/
public abstract class CheckBoxLabelProvider extends ColumnLabelProvider {
/** {@link JFaceResources} id for checked image. */
private static final String CHECKED_KEY = "CHECKED";
/** {@link JFaceResources} id for unchecked image. */
private static final String UNCHECKED_KEY = "UNCHECKED";
/** {@link JFaceResources} id for disabled, unchecked image. */
private static final String DISABLED_UNCHECKED_KEY = "DISABLED_UNCHECKED";
/** {@link JFaceResources} id for disabled, checked image. */
private static final String DISABLED_CHECKED_KEY = "DISABLED_CHECKED";
/** Constructor. */
public CheckBoxLabelProvider(ColumnViewer viewer) {
if (getImageRegistry().getDescriptor(CHECKED_KEY) == null) {
getImageRegistry().put(UNCHECKED_KEY,
makeShot(viewer.getControl().getShell(), false, true));
getImageRegistry().put(CHECKED_KEY,
makeShot(viewer.getControl().getShell(), true, true));
getImageRegistry().put(DISABLED_UNCHECKED_KEY,
makeShot(viewer.getControl().getShell(), false, false));
getImageRegistry().put(DISABLED_CHECKED_KEY,
makeShot(viewer.getControl().getShell(), true, false));
}
}
/** Creates an image of checkbox SWT control. */
private Image makeShot(Shell shell, boolean checked, boolean enabled) {
Shell s = new Shell(shell, NO_TRIM);
Button b = new Button(s, CHECK);
b.setSelection(checked);
b.setEnabled(enabled);
Point bsize = b.computeSize(DEFAULT, DEFAULT);
b.setSize(bsize);
b.setLocation(0, 0);
s.setSize(bsize);
s.open();
GC gc = new GC(b);
Image image = new Image(shell.getDisplay(), bsize.x, bsize.y);
gc.copyArea(image, 0, 0);
gc.dispose();
s.close();
return image;
}
/** {@inheritDoc} */
@Override
public Image getImage(Object element) {
if (isEnabled(element)) {
if (isChecked(element)) {
return getImageRegistry().get(CHECKED_KEY);
}
return getImageRegistry().get(UNCHECKED_KEY);
}
if (isChecked(element)) {
return getImageRegistry().get(DISABLED_CHECKED_KEY);
}
return getImageRegistry().get(DISABLED_UNCHECKED_KEY);
}
/** {@inheritDoc} */
@Override
public String getText(Object element) {
return "";
}
/** Tests the model objects checked state. */
protected abstract boolean isChecked(Object element);
/** Tests the model objects enabled state. */
protected abstract boolean isEnabled(Object element);
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment