Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 18f6346160d97c039309ac2d0b06361fc79c9893 (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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
/*****************************************************************************
 * Copyright (c) 2010 Atos Origin.
 *
 *    
 * 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:
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
 *  
 *  CEA LIST - Class Adaptation in SysML context, Content and Label provider replacement.
 *
 *****************************************************************************/
package org.eclipse.papyrus.sysml.diagram.common.dialogs;

import java.util.List;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.ISpecializationType;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.window.Window;
import org.eclipse.papyrus.infra.services.edit.commands.ConfigureFeatureCommandFactory;
import org.eclipse.papyrus.infra.services.edit.commands.IConfigureCommandFactory;
import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
import org.eclipse.papyrus.infra.widgets.editors.TreeSelectorDialog;
import org.eclipse.papyrus.sysml.diagram.common.Activator;
import org.eclipse.papyrus.sysml.diagram.common.messages.Messages;
import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider;
import org.eclipse.papyrus.uml.tools.utils.NamedElementUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.FormDialog;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.uml2.uml.Namespace;
import org.eclipse.uml2.uml.UMLPackage;

/**
 * Dialog for initialization of Property type (the type is either selected or created).
 */
public class CreateOrSelectTypeDialog extends FormDialog {

	protected Button creationRadio;

	protected Button selectionRadio;

	protected Text newTypeNameText;

	protected Text newTypeContainerNameText;

	protected Button newTypeContainerButton;

	protected String newTypeName = null;

	protected ICommand newTypeCreateCommand = null;

	protected EObject newTypeContainer = null;

	protected Text existingTypeNameText;

	protected Button existingTypeButton;

	protected EObject existingType = null;

	protected EObject defaultContainer;

	protected ILabelProvider labelProvider;

	protected IElementType elementType;

	protected EStructuralFeature editedFeature;

	protected EClass elementEClass;

	protected IElementType containerType;

	protected EStructuralFeature containerFeature;

	protected EClass containerEClass;

	protected List<?> notWantedMetaclasses;

	/**
	 * Create a new dialog to initialize an ActivityParameterNode.
	 * 
	 * @param shell
	 *        parent shell
	 * @param owner
	 *        the activity that owns the action
	 */
	public CreateOrSelectTypeDialog(Shell shell, EObject defaultContainer, IElementType elementType, EStructuralFeature editedFeature, EClass elementEClass, IElementType containerType, EStructuralFeature containerFeature, EClass containerEClass) {
		super(shell);
		this.defaultContainer = defaultContainer;
		this.elementType = elementType;
		this.editedFeature = editedFeature;
		this.elementEClass = elementEClass;
		this.containerType = containerType;
		this.containerFeature = containerFeature;
		this.containerEClass = containerEClass;
		this.labelProvider = new UMLLabelProvider();
	}

	/**
	 * Create a new dialog to initialize an ActivityParameterNode.
	 * This dialog will filter certain Stereotypes
	 * @param shell
	 *        parent shell
	 * @param owner
	 *        the activity that owns the action
	 */
	public CreateOrSelectTypeDialog(Shell shell, EObject defaultContainer, IElementType elementType, EStructuralFeature editedFeature, EClass elementEClass, IElementType containerType, EStructuralFeature containerFeature, EClass containerEClass, List<?> notWantedMetaclasses) {
		this(shell, defaultContainer, elementType, editedFeature, elementEClass, containerType, containerFeature, containerEClass);
		this.notWantedMetaclasses = notWantedMetaclasses;
	}

	protected String getDialogTitle() {
		return Messages.CreateOrSelectTypeDialog_DialogTitle;
	}

	protected String getSelectionSectionTitle() {
		return Messages.CreateOrSelectTypeDialog_SelectionSectionTitle;
	}

	protected String getSelectionSectionRadioLabel() {
		return Messages.CreateOrSelectTypeDialog_SelectionSectionRadioLabel;
	}

	protected String getCreationSectionTitle() {
		return Messages.CreateOrSelectTypeDialog_CreationSectionTitle;
	}

	protected String getCreationSectionRadioLabel() {
		return Messages.CreateOrSelectTypeDialog_CreationSectionRadioLabel;
	}

	protected String getNewTypeNameLabel() {
		return Messages.CreateOrSelectTypeDialog_NewTypeNameLabel;
	}

	protected String getNewTypeContainerNameLabel() {
		return Messages.CreateOrSelectTypeDialog_NewTypeContainerNameLabel;
	}

	protected String getNewTypeContainerDialogTitle() {
		return Messages.CreateOrSelectTypeDialog_SelectNewTypeContainerDialogTitle;
	}

	protected String getNewTypeContainerDialogMessage() {
		return Messages.CreateOrSelectTypeDialog_SelectNewTypeContainerDialogMessage;
	}

	protected String getTypeDialogTitle() {
		return Messages.CreateOrSelectTypeDialog_SelectTypeDialogTitle;
	}

	protected String getTypeDialogMessage() {
		return Messages.CreateOrSelectTypeDialog_SelectTypeDialogMessage;
	}

	/**
	 * Create the form to :
	 * 
	 * - ask the user to choose or create an existing element.
	 * 
	 * @see org.eclipse.ui.forms.FormDialog#createFormContent(org.eclipse.ui.forms.IManagedForm)
	 */
	@Override
	protected void createFormContent(IManagedForm pForm) {
		pForm.getForm().setText(getDialogTitle());
		ScrolledForm scrolledForm = pForm.getForm();
		FormToolkit toolkit = pForm.getToolkit();
		Composite parent = scrolledForm.getBody();
		parent.setLayout(new GridLayout());

		createFormCreationSection(scrolledForm.getBody(), toolkit);
		createFormSelectionSection(scrolledForm.getBody(), toolkit);

		refreshSectionsEnable(false);
		hookListeners();
		// invoked name is set after listeners, since we count on listener to update it properly
		setNewTypeContainer(defaultContainer);
		setNewTypeName(null);

		scrolledForm.reflow(true);
	}

	/**
	 * Adds buttons to this dialog's button bar.
	 * 
	 * @param parent
	 *        the button bar composite
	 */
	@Override
	protected void createButtonsForButtonBar(Composite parent) {
		super.createButtonsForButtonBar(parent);
		refreshOkButton();
	}

	/**
	 * Create the section to ask the user to choose an existing element.
	 * 
	 * @param pParent
	 *        the section's parent widget
	 * @param pToolkit
	 *        the form toolkit
	 */
	protected void createFormSelectionSection(Composite pParent, FormToolkit pToolkit) {
		// create the section
		String lSectionTitle = getSelectionSectionTitle();
		Section lSection = pToolkit.createSection(pParent, Section.EXPANDED | Section.TITLE_BAR);
		lSection.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		if(lSectionTitle != null) {
			lSection.setText(lSectionTitle);
		}

		ScrolledForm lInsideScrolledForm = pToolkit.createScrolledForm(lSection);
		lInsideScrolledForm.setExpandHorizontal(true);
		lInsideScrolledForm.setExpandVertical(true);
		Composite lBody = lInsideScrolledForm.getBody();

		GridLayout lLayout = new GridLayout();
		lLayout.numColumns = 3;
		lBody.setLayout(lLayout);

		// content of the section
		selectionRadio = pToolkit.createButton(lBody, getSelectionSectionRadioLabel(), SWT.RADIO);
		selectionRadio.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));

		// manage elementType selection
		pToolkit.createLabel(lBody, elementType.getDisplayName(), SWT.NONE);
		existingTypeNameText = pToolkit.createText(lBody, "", SWT.BORDER | SWT.READ_ONLY);
		existingTypeNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		existingTypeButton = pToolkit.createButton(lBody, "...", SWT.FLAT);

		Image image = Activator.getInstance().getImage(elementType.getEClass());
		if(elementEClass != null) {
			image = Activator.getInstance().getImage(elementEClass);
		}

		existingTypeButton.setImage(image);
		existingTypeButton.setLayoutData(new GridData(SWT.NONE));

		lInsideScrolledForm.reflow(true);
		lSection.setClient(lInsideScrolledForm);
	}

	/**
	 * Create the section to ask the user to create an invoked element.
	 * 
	 * @param pParent
	 *        the section's parent widget
	 * @param pToolkit
	 *        the form toolkit
	 */
	protected void createFormCreationSection(Composite pParent, FormToolkit pToolkit) {
		// create the section
		String lSectionTitle = getCreationSectionTitle();
		Section lSection = pToolkit.createSection(pParent, Section.EXPANDED | Section.TITLE_BAR);
		lSection.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		if(lSectionTitle != null) {
			lSection.setText(lSectionTitle);
		}

		ScrolledForm lInsideScrolledForm = pToolkit.createScrolledForm(lSection);
		lInsideScrolledForm.setExpandHorizontal(true);
		lInsideScrolledForm.setExpandVertical(true);
		Composite lBody = lInsideScrolledForm.getBody();

		GridLayout lLayout = new GridLayout();
		lLayout.numColumns = 3;
		lBody.setLayout(lLayout);

		// content of the section
		creationRadio = pToolkit.createButton(lBody, getCreationSectionRadioLabel(), SWT.RADIO);
		creationRadio.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));

		pToolkit.createLabel(lBody, getNewTypeNameLabel(), SWT.NONE);
		newTypeNameText = pToolkit.createText(lBody, "", SWT.BORDER);
		newTypeNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
		newTypeNameText.setFocus();

		// manage type selection
		pToolkit.createLabel(lBody, getNewTypeContainerNameLabel(), SWT.NONE);
		newTypeContainerNameText = pToolkit.createText(lBody, labelProvider.getText(newTypeContainer), SWT.BORDER | SWT.READ_ONLY);
		newTypeContainerNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		newTypeContainerButton = pToolkit.createButton(lBody, "...", SWT.FLAT);
		Image image = Activator.getInstance().getImage(containerType.getEClass());
		if(containerEClass != null) {
			image = Activator.getInstance().getImage(containerEClass);
		}
		newTypeContainerButton.setImage(image);
		newTypeContainerButton.setLayoutData(new GridData(SWT.NONE));

		lInsideScrolledForm.reflow(true);
		lSection.setClient(lInsideScrolledForm);
	}


	@Override
	protected void okPressed() {

		// Build type creation command if needed
		boolean isSelectionMode = selectionRadio.getSelection();
		if(!isSelectionMode) {
			// Creation mode - Prepare type creation command and set existing type to null.
			existingType = null;
			buildNewTypeCreateCommand();

		} else {
			// Selection mode - Set the type creation command to null.
			newTypeCreateCommand = null;
		}

		super.okPressed();
	}

	protected void buildNewTypeCreateCommand() {
		// The new element is expected to be a NamedElement.
		IElementEditService commandService = ElementEditServiceUtils.getCommandProvider(newTypeContainer);
		if(commandService != null) {
			CreateElementRequest createTypeRequest = new CreateElementRequest(newTypeContainer, elementType);
			createTypeRequest.setParameter(IConfigureCommandFactory.CONFIGURE_COMMAND_FACTORY_ID, new ConfigureFeatureCommandFactory(UMLPackage.eINSTANCE.getNamedElement_Name(), newTypeNameText.getText()));
			newTypeCreateCommand = commandService.getEditCommand(createTypeRequest);
		}
	}

	public ICommand getNewTypeCreateCommand() {
		return newTypeCreateCommand;
	}

	public String getNewTypeName() {
		return newTypeNameText.getText();
	}

	public EObject getExistingType() {
		return existingType;
	}

	/**
	 * Add listeners to widgets
	 */
	protected void hookListeners() {
		// listener to choose active section
		SelectionListener selectCreateListener = new SelectionAdapter() {

			/**
			 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
			 */
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(creationRadio.equals(e.getSource())) {
					refreshSectionsEnable(false);
				} else {
					refreshSectionsEnable(true);
				}
				refreshOkButton();
			}
		};
		selectionRadio.addSelectionListener(selectCreateListener);
		creationRadio.addSelectionListener(selectCreateListener);

		// listener to select existing element
		SelectionListener selectBtnListener = new SelectionAdapter() {

			/**
			 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
			 */
			@Override
			public void widgetSelected(SelectionEvent e) {
				handleChooseType();
				refreshOkButton();
			}
		};
		existingTypeButton.addSelectionListener(selectBtnListener);

		// listener to existing element name
		ModifyListener lNameListener = new ModifyListener() {

			/**
			 * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
			 */
			public void modifyText(ModifyEvent e) {
				setNewTypeName(existingTypeNameText.getText());
			}
		};
		existingTypeNameText.addModifyListener(lNameListener);

		// listener to select new element type container
		SelectionListener selectTypeBtnListener = new SelectionAdapter() {

			/**
			 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
			 */
			@Override
			public void widgetSelected(SelectionEvent e) {
				handleChooseNewTypeContainer();
				// reset name if not set
				if(newTypeName == null) {
					setNewTypeName(null);
				}
				refreshOkButton();
			}
		};
		newTypeContainerButton.addSelectionListener(selectTypeBtnListener);

		// listener to new element name
		ModifyListener lNewNameListener = new ModifyListener() {

			/**
			 * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
			 */
			public void modifyText(ModifyEvent e) {
				validateNewTypeName();
				refreshOkButton();
			}
		};
		newTypeNameText.addModifyListener(lNewNameListener);
	}

	/**
	 * Set the name of the new type
	 * 
	 * @param text
	 *        the text string or null for auto-initialization
	 */
	protected void setNewTypeName(String text) {
		String name = text;
		if(text == null) {
			name = NamedElementUtil.getDefaultNameWithIncrementFromBase(elementType.getEClass().getName(), newTypeContainer.eContents());
			if(elementEClass != null) {
				name = NamedElementUtil.getDefaultNameWithIncrementFromBase(elementEClass.getName(), newTypeContainer.eContents());
			}
			newTypeNameText.setText(name);

		} else {
			newTypeNameText.setText(name);
			newTypeName = name;
		}

		validateNewTypeName();
		refreshOkButton();
	}

	protected void validateNewTypeName() {
		if(isValidName(newTypeContainer, newTypeNameText.getText())) {
			Color black = newTypeNameText.getDisplay().getSystemColor(SWT.COLOR_BLACK);
			newTypeNameText.setForeground(black);

		} else {
			Color red = newTypeNameText.getDisplay().getSystemColor(SWT.COLOR_RED);
			newTypeNameText.setForeground(red);
		}
	}

	protected boolean isValidName(EObject container, String newName) {
		boolean isValid = true;
		if(container instanceof Namespace) {
			if(((Namespace)container).getOwnedMember(newName) != null) {
				isValid = false;
			}
		}

		return isValid;
	}

	/** Open the dialog to choose an existing type */
	protected void handleChooseType() {

		TreeSelectorDialog dialog = new TreeSelectorDialog(getShell());

		dialog.setMessage(getTypeDialogMessage());
		dialog.setTitle(getTypeDialogTitle());
		dialog.setInput(EcoreUtil.getRootContainer(defaultContainer));

		ServiceEditContentProvider provider = new ServiceEditContentProvider(elementType, editedFeature, EcoreUtil.getRootContainer(defaultContainer));
		provider.setNotWantedMetaclasses(notWantedMetaclasses);

		dialog.setContentProvider(provider);
		dialog.setLabelProvider(labelProvider);
		
		if(dialog.open() == Window.OK) {
			Object result = dialog.getResult()[0];
			if(result instanceof IAdaptable) {
				result = ((IAdaptable)result).getAdapter(EObject.class);
			}

			if(result instanceof EObject) {
				setExistingTypeSelection((EObject)result);
			} else {
				setExistingTypeSelection(null);
			}
		}
	}

	/**
	 * Set the existing type selected (if selection mode is chosen)
	 * 
	 * @param invokedElement
	 *        the selected element
	 */
	protected void setExistingTypeSelection(EObject type) {
		if(type == null) {
			existingTypeNameText.setText("");
		} else {
			existingType = type;
			existingTypeNameText.setText(labelProvider.getText(existingType));
		}
	}

	/** Open the dialog to choose new type container */
	protected void handleChooseNewTypeContainer() {

		TreeSelectorDialog dialog = new TreeSelectorDialog(getShell());

		dialog.setMessage(getNewTypeContainerDialogMessage());
		dialog.setTitle(getNewTypeContainerDialogTitle());
		dialog.setInput(EcoreUtil.getRootContainer(defaultContainer));

		ServiceEditContentProvider provider = new ServiceEditContentProvider(containerType, containerFeature, EcoreUtil.getRootContainer(defaultContainer));
		dialog.setContentProvider(provider);
		dialog.setLabelProvider(labelProvider);

		if(dialog.open() == Window.OK) {
			Object result = dialog.getResult()[0];
			if(result instanceof IAdaptable) {
				result = ((IAdaptable)result).getAdapter(EObject.class);
			}

			if(result instanceof EObject) {
				setNewTypeContainer((EObject)result);
			} else {
				setNewTypeContainer(null);
			}
		}
	}

	/**
	 * Define the type of the object that will be created (if creation mode is chosen)
	 * 
	 * @param the
	 *        selected parent
	 */
	protected void setNewTypeContainer(EObject container) {

		if((containerType instanceof ISpecializationType) && ((ISpecializationType)containerType).getMatcher().matches(container)) {
			newTypeContainer = container;
			newTypeContainerNameText.setText(labelProvider.getText(newTypeContainer));

		} else if(containerType.getEClass().isInstance(container)) {
			newTypeContainer = container;
			newTypeContainerNameText.setText(labelProvider.getText(newTypeContainer));

		} else {
			newTypeContainer = null;
			newTypeContainerNameText.setText("");
		}
	}

	/**
	 * Refresh the enabled and disabled elements in various sections
	 * 
	 * @param isSelectionSelected
	 *        true if we choose to select an existing element, false if we choose to create an element
	 */
	private void refreshSectionsEnable(boolean isSelectionSelected) {
		// handle radio button value
		if(isSelectionSelected) {
			creationRadio.setSelection(false);
			if(!selectionRadio.getSelection()) {
				selectionRadio.setSelection(true);
			}
		} else {
			selectionRadio.setSelection(false);
			if(!creationRadio.getSelection()) {
				creationRadio.setSelection(true);
			}
		}
		// handle disabled section
		existingTypeNameText.setEnabled(isSelectionSelected);
		existingTypeButton.setEnabled(isSelectionSelected);
		newTypeNameText.setEnabled(!isSelectionSelected);
		newTypeNameText.setFocus();
		newTypeContainerNameText.setEnabled(!isSelectionSelected);
		newTypeContainerButton.setEnabled(!isSelectionSelected);
	}


	/** Refresh the OK button activation */
	protected void refreshOkButton() {
		boolean isSelectionSelected = selectionRadio.getSelection();
		if(getButton(IDialogConstants.OK_ID) != null && !getButton(IDialogConstants.OK_ID).isDisposed()) {
			if(isSelectionSelected) {
				getButton(IDialogConstants.OK_ID).setEnabled(existingType != null);
			} else {
				getButton(IDialogConstants.OK_ID).setEnabled((newTypeContainer != null) && (isValidName(newTypeContainer, newTypeNameText.getText())));
			}
		}
	}
}

Back to the top