Package: AcceleoPropertiesFilesTab$1

AcceleoPropertiesFilesTab$1

nameinstructionbranchcomplexitylinemethod
modifyText(ModifyEvent)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
{...}
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2008, 2012 Obeo.
3: * All rights reserved. This program and the accompanying materials
4: * are made available under the terms of the Eclipse Public License v1.0
5: * which accompanies this distribution, and is available at
6: * http://www.eclipse.org/legal/epl-v10.html
7: *
8: * Contributors:
9: * Obeo - initial API and implementation
10: *******************************************************************************/
11: package org.eclipse.acceleo.internal.ide.ui.launching;
12:
13: import org.eclipse.acceleo.ide.ui.AcceleoUIActivator;
14: import org.eclipse.acceleo.internal.ide.ui.AcceleoUIMessages;
15: import org.eclipse.core.runtime.CoreException;
16: import org.eclipse.debug.core.ILaunchConfiguration;
17: import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
18: import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
19: import org.eclipse.debug.ui.ILaunchConfigurationTab;
20: import org.eclipse.swt.SWT;
21: import org.eclipse.swt.events.ModifyEvent;
22: import org.eclipse.swt.events.ModifyListener;
23: import org.eclipse.swt.graphics.Font;
24: import org.eclipse.swt.graphics.Image;
25: import org.eclipse.swt.layout.GridData;
26: import org.eclipse.swt.layout.GridLayout;
27: import org.eclipse.swt.widgets.Composite;
28: import org.eclipse.swt.widgets.Group;
29: import org.eclipse.swt.widgets.Text;
30: import org.eclipse.swt.widgets.ToolBar;
31: import org.eclipse.swt.widgets.ToolItem;
32: import org.eclipse.ui.ISharedImages;
33: import org.eclipse.ui.PlatformUI;
34:
35: /**
36: * The Acceleo properties files tab.
37: *
38: * @author <a href="mailto:stephane.begaudeau@obeo.fr">Stephane Begaudeau</a>
39: */
40: public class AcceleoPropertiesFilesTab extends AbstractLaunchConfigurationTab {
41:
42:         /**
43:          * The arguments text widget.
44:          */
45:         private Text argumentsText;
46:
47:         /**
48:          * {@inheritDoc}
49:          *
50:          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
51:          */
52:         public void createControl(Composite parent) {
53:                 Composite g = new Composite(parent, SWT.NONE);
54:                 g.setLayout(new GridLayout(1, false));
55:                 g.setFont(parent.getFont());
56:                 GridData gd = new GridData(GridData.FILL_BOTH);
57:                 gd.horizontalSpan = 1;
58:                 g.setLayoutData(gd);
59:
60:                 ((GridLayout)g.getLayout()).verticalSpacing = 0;
61:                 createAcceleoArgumentsEditor(g);
62:                 setControl(g);
63:         }
64:
65:         /**
66:          * Creates the widgets for specifying the arguments.
67:          *
68:          * @param parent
69:          * the parent composite
70:          */
71:         protected void createAcceleoArgumentsEditor(Composite parent) {
72:                 Font font = parent.getFont();
73:                 Group mainGroup = createGroup(parent, AcceleoUIMessages
74:                                 .getString("AcceleoPropertiesFilesTab.Arguments"), 2, 1, //$NON-NLS-1$
75:                                 GridData.FILL_HORIZONTAL);
76:                 Composite comp = createComposite(mainGroup, font, 2, 2, GridData.FILL_BOTH, 0, 0);
77:                 argumentsText = new Text(comp, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL);
78:                 GridData gd = new GridData(GridData.FILL_BOTH);
79:                 final int heightHint = 150;
80:                 gd.heightHint = heightHint;
81:                 gd.widthHint = 100;
82:                 gd.horizontalSpan = 2;
83:                 argumentsText.setLayoutData(gd);
84:                 argumentsText.addModifyListener(new ModifyListener() {
85:                         public void modifyText(ModifyEvent e) {
86:                                 updateLaunchConfigurationDialog();
87:                         }
88:                 });
89:
90:                 createHelpButton(comp, AcceleoUIMessages.getString("AcceleoPropertiesFilesTab.Help.Properties")); //$NON-NLS-1$
91:         }
92:
93:         /**
94:          * Creates a help button in the given parent with the given help message and the given help ID.
95:          *
96:          * @param parent
97:          * The composite
98:          * @param helpMessage
99:          * The help message seen by the user
100:          * @return The toolbar with the button.
101:          */
102:         private ToolBar createHelpButton(Composite parent, String helpMessage) {
103:                 Image image = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_LCL_LINKTO_HELP);
104:                 ToolBar result = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
105:                 ((GridLayout)parent.getLayout()).numColumns++;
106:                 result.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER
107:                                 | GridData.VERTICAL_ALIGN_BEGINNING));
108:                 ToolItem item = new ToolItem(result, SWT.NONE);
109:                 item.setImage(image);
110:                 if (helpMessage != null && !"".equals(helpMessage)) { //$NON-NLS-1$
111:                         item.setToolTipText(helpMessage);
112:                 }
113:                 return result;
114:         }
115:
116:         /**
117:          * Creates a Composite widget.
118:          *
119:          * @param parent
120:          * the parent composite to add this composite to
121:          * @param font
122:          * is the font
123:          * @param columns
124:          * the number of columns within the composite
125:          * @param hspan
126:          * the horizontal span the composite should take up on the parent
127:          * @param fill
128:          * the style for how this composite should fill into its parent Can be one of
129:          * <code>GridData.FILL_HORIZONAL</code>, <code>GridData.FILL_BOTH</code> or
130:          * <code>GridData.FILL_VERTICAL</code>
131:          * @param marginwidth
132:          * the width of the margin to place around the composite (default is 5, specified by
133:          * GridLayout)
134:          * @param marginheight
135:          * the height of the margin to place around the composite (default is 5, specified by
136:          * GridLayout)
137:          * @return the new group
138:          */
139:         private Composite createComposite(Composite parent, Font font, int columns, int hspan, int fill,
140:                         int marginwidth, int marginheight) {
141:                 Composite g = new Composite(parent, SWT.NONE);
142:                 GridLayout layout = new GridLayout(columns, false);
143:                 layout.marginWidth = marginwidth;
144:                 layout.marginHeight = marginheight;
145:                 g.setLayout(layout);
146:                 g.setFont(font);
147:                 GridData gd = new GridData(fill);
148:                 gd.horizontalSpan = hspan;
149:                 g.setLayoutData(gd);
150:                 return g;
151:         }
152:
153:         /**
154:          * Creates a Group widget.
155:          *
156:          * @param parent
157:          * the parent composite to add this group to
158:          * @param text
159:          * the text for the heading of the group
160:          * @param columns
161:          * the number of columns within the group
162:          * @param hspan
163:          * the horizontal span the group should take up on the parent
164:          * @param fill
165:          * the style for how this composite should fill into its parent Can be one of
166:          * <code>GridData.FILL_HORIZONAL</code>, <code>GridData.FILL_BOTH</code> or
167:          * <code>GridData.FILL_VERTICAL</code>
168:          * @return the new group
169:          */
170:         private Group createGroup(Composite parent, String text, int columns, int hspan, int fill) {
171:                 Group g = new Group(parent, SWT.NONE);
172:                 g.setLayout(new GridLayout(columns, false));
173:                 g.setText(text);
174:                 g.setFont(parent.getFont());
175:                 GridData gd = new GridData(fill);
176:                 gd.horizontalSpan = hspan;
177:                 g.setLayoutData(gd);
178:                 return g;
179:         }
180:
181:         /**
182:          * {@inheritDoc}
183:          *
184:          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
185:          */
186:         public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
187:                 configuration.setAttribute(IAcceleoLaunchConfigurationConstants.ATTR_ARGUMENTS, ""); //$NON-NLS-1$
188:         }
189:
190:         /**
191:          * {@inheritDoc}
192:          *
193:          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
194:          */
195:         public void initializeFrom(ILaunchConfiguration configuration) {
196:                 updateAcceleoArgumentsFromConfig(configuration);
197:         }
198:
199:         /**
200:          * Loads the arguments from the launch configuration's preference store.
201:          *
202:          * @param config
203:          * the configuration to load the arguments
204:          */
205:         protected void updateAcceleoArgumentsFromConfig(ILaunchConfiguration config) {
206:                 String args = ""; //$NON-NLS-1$
207:                 try {
208:                         args = config.getAttribute(IAcceleoLaunchConfigurationConstants.ATTR_ARGUMENTS, ""); //$NON-NLS-1$
209:                 } catch (CoreException e) {
210:                         AcceleoUIActivator.getDefault().getLog().log(e.getStatus());
211:                 }
212:                 argumentsText.setText(args);
213:         }
214:
215:         /**
216:          * {@inheritDoc}
217:          *
218:          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
219:          */
220:         public void performApply(ILaunchConfigurationWorkingCopy configuration) {
221:                 configuration.setAttribute(IAcceleoLaunchConfigurationConstants.ATTR_ARGUMENTS, argumentsText
222:                                 .getText());
223:
224:                 // update Java arguments
225:                 AcceleoJavaArgumentsTab argumentTab = null;
226:                 AcceleoMainTab mainTab = null;
227:                 ILaunchConfigurationTab[] tabs = this.getLaunchConfigurationDialog().getTabs();
228:                 for (ILaunchConfigurationTab iLaunchConfigurationTab : tabs) {
229:                         if (iLaunchConfigurationTab instanceof AcceleoJavaArgumentsTab) {
230:                                 argumentTab = (AcceleoJavaArgumentsTab)iLaunchConfigurationTab;
231:                         } else if (iLaunchConfigurationTab instanceof AcceleoMainTab) {
232:                                 mainTab = (AcceleoMainTab)iLaunchConfigurationTab;
233:                         }
234:                 }
235:
236:                 if (argumentTab != null && mainTab != null) {
237:                         argumentTab.updateArguments(configuration, mainTab.getModel().trim(), mainTab.getTarget().trim(),
238:                                         argumentsText.getText());
239:                 }
240:         }
241:
242:         /**
243:          * {@inheritDoc}
244:          *
245:          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
246:          */
247:         public String getName() {
248:                 return AcceleoUIMessages.getString("AcceleoPropertiesFilesTab.Name"); //$NON-NLS-1$
249:         }
250:
251:         /**
252:          * Returns the content of the properties files text area.
253:          *
254:          * @return The content of the properties files text area.
255:          */
256:         public String getPropertiesFiles() {
257:                 return argumentsText.getText();
258:         }
259:
260: }