Skip to main content
summaryrefslogtreecommitdiffstats
blob: 244b498e1a1f66a55986b23de8d58dc6b49a7840 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*******************************************************************************
 * Copyright (c) 2010 BestSolution.at and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
 *     Sopot Cela <sopotcela@gmail.com>
 ******************************************************************************/
package org.eclipse.e4.internal.tools.wizards.classes;

import java.util.Set;

import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeanProperties;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.e4.internal.tools.wizards.classes.AbstractNewClassPage.JavaClass;
import org.eclipse.e4.internal.tools.wizards.classes.templates.HandlerTemplate;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jface.databinding.swt.IWidgetValueProperty;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

public class NewHandlerClassWizard extends AbstractNewClassWizard {
	private String initialString;

	public NewHandlerClassWizard(String contributionURI) {
		this.initialString = contributionURI;
	}
	
	public NewHandlerClassWizard() {
		// Intentially left empty 
	}

	@Override
	protected String getContent() {
		HandlerTemplate template = new HandlerTemplate();
		return template.generate(getDomainClass());
	}
	
	@Override
	public void addPages() {
		addPage(new AbstractNewClassPage("Classinformation",
				"New Handler",
				"Create a new handler class", root, ResourcesPlugin.getWorkspace().getRoot(),initialString) {

			@Override
			protected JavaClass createInstance() {
				return new HandlerClass(root);
			}

			@Override
			protected void createFields(Composite parent, DataBindingContext dbc) {
				IWidgetValueProperty textProp = WidgetProperties
						.text(SWT.Modify);

				{
					Label l = new Label(parent, SWT.NONE);
					l.setText("Execute Method");

					Text t = new Text(parent, SWT.BORDER);
					t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
					dbc.bindValue(
							textProp.observe(t),
							BeanProperties.value("executeMethodName").observe(
									getClazz()));

					l = new Label(parent, SWT.NONE);
				}

				{
					Label l = new Label(parent, SWT.NONE);
					l.setText("Can-Execute Method");

					Text t = new Text(parent, SWT.BORDER);
					t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
					dbc.bindValue(textProp.observe(t),
							BeanProperties.value("canExecuteMethodName")
									.observe(getClazz()));
					dbc.bindValue(
							WidgetProperties.enabled().observe(t),
							BeanProperties.value("useCanExecute").observe(
									getClazz()));

					Button b = new Button(parent, SWT.CHECK);
					dbc.bindValue(
							WidgetProperties.selection().observe(b),
							BeanProperties.value("useCanExecute").observe(
									getClazz()));
				}
			}
		});
	}
	
	@Override
	protected Set<String> getRequiredBundles() {
		Set<String> set = super.getRequiredBundles();
		set.add("org.eclipse.e4.core.di");
		return set;
	}
	
	public static class HandlerClass extends JavaClass {
		private String executeMethodName = "execute";
		private String canExecuteMethodName = "canExecute";
		private boolean useCanExecute = false;

		public HandlerClass(IPackageFragmentRoot root) {
			super(root);
		}

		public String getExecuteMethodName() {
			return executeMethodName;
		}

		public void setExecuteMethodName(String executeMethodName) {
			support.firePropertyChange("executeMethodName",
					this.executeMethodName,
					this.executeMethodName = executeMethodName);
		}

		public String getCanExecuteMethodName() {
			return canExecuteMethodName;
		}

		public void setCanExecuteMethodName(String canExecuteMethodName) {
			support.firePropertyChange("canExecuteMethodName",
					this.canExecuteMethodName,
					this.canExecuteMethodName = canExecuteMethodName);
		}

		public boolean isUseCanExecute() {
			return useCanExecute;
		}

		public void setUseCanExecute(boolean useCanExecute) {
			support.firePropertyChange("useCanExecute", this.useCanExecute,
					this.useCanExecute = useCanExecute);
		}
	}
}

Back to the top