01: package org.drools.eclipse.flow.common.view.property;
02:
03: /*
04: * Copyright 2005 JBoss Inc
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import org.eclipse.jface.viewers.DialogCellEditor;
20: import org.eclipse.jface.window.Window;
21: import org.eclipse.swt.widgets.Composite;
22: import org.eclipse.swt.widgets.Control;
23: import org.eclipse.swt.widgets.Shell;
24:
25: /**
26: * Cell editor for a JavaBean.
27: *
28: * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
29: */
30: public abstract class BeanDialogCellEditor extends DialogCellEditor {
31:
32: public BeanDialogCellEditor(Composite parent) {
33: super (parent);
34: }
35:
36: protected Object openDialogBox(Control cellEditorWindow) {
37: EditBeanDialog dialog = createDialog(cellEditorWindow
38: .getShell());
39: Object value = getValue();
40: if (value != null) {
41: dialog.setValue(value);
42: }
43: int result = dialog.open();
44: if (result == Window.CANCEL) {
45: return null;
46: }
47: return dialog.getValue();
48: }
49:
50: protected abstract EditBeanDialog createDialog(Shell shell);
51:
52: protected void updateContents(Object value) {
53: getDefaultLabel().setText(getLabelText(value));
54: }
55:
56: protected String getLabelText(Object value) {
57: if (value == null) {
58: return "";
59: }
60: return value.toString();
61: }
62: }
|