View | Details | Raw Unified | Return to bug 141743 | Differences between
and this patch

Collapse All | Expand All

(-)templates/editor/Editor.javajet (-1 / +362 lines)
Lines 10-15 Link Here
10
importManager.markImportLocation(stringBuffer);%>
10
importManager.markImportLocation(stringBuffer);%>
11
11
12
<%
12
<%
13
importManager.registerInnerClass("UndoablePropertySheetEntry");
14
importManager.registerInnerClass("SetValueCommand");
15
importManager.registerInnerClass("ResetValueCommand");
16
importManager.registerInnerClass("UpdatableActionGroup");
17
importManager.registerInnerClass(genEditor.getClassName() + "ContextMenuProvider");
18
if (!isRichClientPlatform) {
19
	importManager.registerInnerClass("ResourceTracker");
20
}
21
13
importManager.addImport("java.io.IOException");
22
importManager.addImport("java.io.IOException");
14
importManager.addImport("java.util.ArrayList");
23
importManager.addImport("java.util.ArrayList");
15
importManager.addImport("java.util.Collections");
24
importManager.addImport("java.util.Collections");
Lines 197-202 Link Here
197
	}
206
	}
198
207
199
	/**
208
	/**
209
	 * Copied from <code>org.eclipse.gef.ui.properties.UndoablePropertySheetEntry</code> to provide EMF compatibility.
210
	 * @generated
211
	 */
212
	private static final class UndoablePropertySheetEntry extends <%=importManager.getImportedName("org.eclipse.ui.views.properties.PropertySheetEntry")%> {
213
		/**
214
		 * @generated
215
		 */
216
		private static class SetValueCommand extends <%=importManager.getImportedName("org.eclipse.gef.commands.Command")%> {
217
			/**
218
			 * @generated
219
			 */
220
			protected Object propertyValue;
221
			/**
222
			 * @generated
223
			 */
224
			protected Object propertyName;
225
			/**
226
			 * @generated
227
			 */
228
			protected Object undoValue;
229
			/**
230
			 * @generated
231
			 */
232
			protected boolean resetOnUndo;
233
			/**
234
			 * @generated
235
			 */
236
			protected <%=importManager.getImportedName("org.eclipse.ui.views.properties.IPropertySource")%> target;
237
		
238
			/**
239
			 * @generated
240
			 */
241
			public SetValueCommand() {
242
				super(""); //$NON-NLS-1$
243
			}
244
		
245
			/**
246
			 * @generated
247
			 */
248
			public SetValueCommand(String propLabel) {
249
				super(<%=importManager.getImportedName("java.text.MessageFormat")%>.format("Set {0} property", new Object[]{propLabel}).trim());
250
			}
251
		
252
			/**
253
			 * @generated
254
			 */
255
			public boolean canExecute() {
256
				return true;
257
			}
258
		
259
			/**
260
			 * @generated
261
			 */
262
			public void execute() {
263
				/*
264
				 * Fix for Bug# 54250
265
				 * IPropertySource.isPropertySet(String) returns false both when there is no default 
266
				 * value, and when there is a default value and the property is set to that value.
267
				 * To correctly determine if a reset should be done during undo, we compare the
268
				 * return value of isPropertySet(String) before and after setPropertyValue(...) is
269
				 * invoked.  If they are different (it must have been false before and true after --
270
				 * it cannot be the other way around), then that means we need to reset.
271
				 */
272
				boolean wasPropertySet = getTarget().isPropertySet(propertyName);
273
				undoValue = getTarget().getPropertyValue(propertyName);
274
				if (undoValue instanceof <%=importManager.getImportedName("org.eclipse.ui.views.properties.IPropertySource")%>) {
275
					undoValue = ((<%=importManager.getImportedName("org.eclipse.ui.views.properties.IPropertySource")%>)undoValue).getEditableValue();
276
				} else if (undoValue instanceof <%=importManager.getImportedName("org.eclipse.emf.edit.provider.IItemPropertySource")%>) {
277
					undoValue = ((<%=importManager.getImportedName("org.eclipse.emf.edit.provider.IItemPropertySource")%>)undoValue).getEditableValue(propertyName);
278
				}
279
				if (propertyValue instanceof <%=importManager.getImportedName("org.eclipse.ui.views.properties.IPropertySource")%>)
280
					propertyValue = ((<%=importManager.getImportedName("org.eclipse.ui.views.properties.IPropertySource")%>)propertyValue).getEditableValue();
281
				getTarget().setPropertyValue(propertyName, propertyValue);
282
				if (getTarget() instanceof <%=importManager.getImportedName("org.eclipse.ui.views.properties.IPropertySource2")%>)
283
					resetOnUndo = !wasPropertySet
284
							&& ((<%=importManager.getImportedName("org.eclipse.ui.views.properties.IPropertySource2")%>)getTarget()).isPropertyResettable(propertyName);
285
				else
286
					resetOnUndo = !wasPropertySet && getTarget().isPropertySet(propertyName);
287
				if (resetOnUndo)
288
					undoValue = null;
289
			}
290
291
			/**
292
			 * @generated
293
			 */
294
			public <%=importManager.getImportedName("org.eclipse.ui.views.properties.IPropertySource")%> getTarget() {
295
				return target;
296
			}
297
		
298
			/**
299
			 * @generated
300
			 */
301
			public void setTarget(<%=importManager.getImportedName("org.eclipse.ui.views.properties.IPropertySource")%> aTarget) {
302
				target = aTarget;
303
			}
304
		
305
			/**
306
			 * @generated
307
			 */
308
			public void redo() {
309
				execute();
310
			}
311
		
312
			/**
313
			 * @generated
314
			 */
315
			public void setPropertyId(Object pName) {
316
				propertyName = pName;
317
			}
318
		
319
			/**
320
			 * @generated
321
			 */
322
			public void setPropertyValue(Object val) {
323
				propertyValue = val;
324
			}
325
		
326
			/**
327
			 * @generated
328
			 */
329
			public void undo() {
330
				if (resetOnUndo)
331
					getTarget().resetPropertyValue(propertyName);
332
				else
333
					getTarget().setPropertyValue(propertyName, undoValue);
334
			}
335
		}
336
337
		/**
338
		 * @generated
339
		 */
340
		private static class ResetValueCommand extends <%=importManager.getImportedName("org.eclipse.gef.commands.Command")%> {
341
			/** 
342
			 * the property that has to be reset 
343
			 * @generated
344
			 */
345
			protected Object propertyName;
346
			/** 
347
			 * the current non-default value of the property 
348
			 * @generated
349
			 */
350
			protected Object undoValue;
351
			/**
352
			 * the property source whose property has to be reset 
353
			 * @generated
354
			 */
355
			protected <%=importManager.getImportedName("org.eclipse.ui.views.properties.IPropertySource")%> target;
356
		
357
			/**
358
			 * Default Constructor: Sets the label for the Command
359
			 * @generated
360
			 */
361
			public ResetValueCommand() {
362
				super("Restore Default Value");
363
			}
364
		
365
			/**
366
			 * Returns <code>true</code> IFF:<br>
367
			 * 1) the target and property have been specified<br>
368
			 * 2) the property has a default value<br>
369
			 * 3) the value set for that property is not the default
370
			 * @generated
371
			 */
372
			public boolean canExecute() {
373
				boolean answer = false;
374
				if (target != null && propertyName != null) {
375
					answer = target.isPropertySet(propertyName);
376
					if (target instanceof <%=importManager.getImportedName("org.eclipse.ui.views.properties.IPropertySource2")%>)
377
						answer = answer 
378
								&& (((<%=importManager.getImportedName("org.eclipse.ui.views.properties.IPropertySource2")%>)target).isPropertyResettable(propertyName));
379
				}
380
				return answer;
381
			}
382
		
383
			/**
384
			 * Caches the undo value and invokes redo()
385
			 * @generated
386
			 */
387
			public void execute() {
388
				undoValue = target.getPropertyValue(propertyName);
389
				if (undoValue instanceof <%=importManager.getImportedName("org.eclipse.ui.views.properties.IPropertySource")%>) {
390
					undoValue = ((<%=importManager.getImportedName("org.eclipse.ui.views.properties.IPropertySource")%>)undoValue).getEditableValue();
391
				} else if (undoValue instanceof <%=importManager.getImportedName("org.eclipse.emf.edit.provider.IItemPropertySource")%>) {
392
					undoValue = ((<%=importManager.getImportedName("org.eclipse.emf.edit.provider.IItemPropertySource")%>)undoValue).getEditableValue(propertyName);
393
				}
394
				redo();
395
			}
396
		
397
			/**
398
			 * Sets the IPropertySource.
399
			 * @param propSource the IPropertySource whose property has to be reset
400
			 * @generated
401
			 */
402
			public void setTarget(<%=importManager.getImportedName("org.eclipse.ui.views.properties.IPropertySource")%> propSource) {
403
				target = propSource;
404
			}
405
		
406
			/**
407
			 * Resets the specified property on the specified IPropertySource
408
			 * @generated
409
			 */
410
			public void redo() {
411
				target.resetPropertyValue(propertyName);
412
			}
413
		
414
			/**
415
			 * Sets the property that is to be reset.
416
			 * @param pName the property to be reset
417
			 * @generated
418
			 */
419
			public void setPropertyId(Object pName) {
420
				propertyName = pName;
421
			}
422
		
423
			/**
424
			 * Restores the non-default value that was reset. 
425
			 * @generated
426
			 */
427
			public void undo() {
428
				target.setPropertyValue(propertyName, undoValue);
429
			}
430
		}
431
432
		/**
433
		 * @generated
434
		 */
435
		private <%=importManager.getImportedName("org.eclipse.gef.commands.CommandStackListener")%> commandStackListener;
436
	
437
		/**
438
		 * @generated
439
		 */
440
		private <%=importManager.getImportedName("org.eclipse.gef.commands.CommandStack")%> stack;
441
	
442
		/**
443
		 * @generated
444
		 */
445
		private UndoablePropertySheetEntry() { }
446
	
447
		/**
448
		 * Constructs the root entry using the given command stack.
449
		 * @param stack the command stack
450
		 * @generated
451
		 */
452
		public UndoablePropertySheetEntry(<%=importManager.getImportedName("org.eclipse.gef.commands.CommandStack")%> stack) {
453
			setCommandStack(stack);
454
		}
455
	
456
		/**
457
		 * @generated
458
		 */
459
		protected <%=importManager.getImportedName("org.eclipse.ui.views.properties.PropertySheetEntry")%> createChildEntry() {
460
			return new UndoablePropertySheetEntry();
461
		}
462
	
463
		/**
464
		 * @generated
465
		 */
466
		public void dispose() {
467
			if (stack != null)
468
				stack.removeCommandStackListener(commandStackListener);
469
			super.dispose();
470
		}
471
	
472
		/**
473
		 * @generated
474
		 */
475
		<%=importManager.getImportedName("org.eclipse.gef.commands.CommandStack")%> getCommandStack() {
476
			//only the root has, and is listening to the command stack
477
			if (getParent() != null)
478
				return ((UndoablePropertySheetEntry)getParent()).getCommandStack();
479
			return stack;
480
		}
481
	
482
		/**
483
		 * @generated
484
		 */
485
		public void resetPropertyValue() {
486
			<%=importManager.getImportedName("org.eclipse.gef.commands.CompoundCommand")%> cc = new <%=importManager.getImportedName("org.eclipse.gef.commands.CompoundCommand")%>();
487
			ResetValueCommand restoreCmd;
488
	
489
			if (getParent() == null)
490
				// root does not have a default value
491
				return;
492
	
493
			//	Use our parent's values to reset our values.
494
			boolean change = false;
495
			Object[] objects = getParent().getValues();
496
			for (int i = 0; i < objects.length; i++) {
497
				<%=importManager.getImportedName("org.eclipse.ui.views.properties.IPropertySource")%> source = getPropertySource(objects[i]);
498
				if (source.isPropertySet(getDescriptor().getId())) {
499
					//source.resetPropertyValue(getDescriptor()getId());
500
					restoreCmd = new ResetValueCommand();
501
					restoreCmd.setTarget(source);
502
					restoreCmd.setPropertyId(getDescriptor().getId());
503
					cc.add(restoreCmd);			
504
					change = true;
505
				}
506
			}
507
			if (change) {
508
				getCommandStack().execute(cc);
509
				refreshFromRoot();
510
			}
511
		}
512
	
513
		/**
514
		 * @generated
515
		 */
516
		void setCommandStack(<%=importManager.getImportedName("org.eclipse.gef.commands.CommandStack")%> stack) {
517
			this.stack = stack;
518
			commandStackListener = new <%=importManager.getImportedName("org.eclipse.gef.commands.CommandStackListener")%>() {
519
				public void commandStackChanged(<%=importManager.getImportedName("java.util.EventObject")%> e) {
520
					refreshFromRoot();
521
				}
522
			};
523
			stack.addCommandStackListener(commandStackListener);
524
		}
525
	
526
		/**
527
		 * @generated
528
		 */
529
		protected void valueChanged(<%=importManager.getImportedName("org.eclipse.ui.views.properties.PropertySheetEntry")%> child) {
530
			valueChanged((UndoablePropertySheetEntry)child,
531
					new <%=importManager.getImportedName("org.eclipse.gef.commands.ForwardUndoCompoundCommand")%>());
532
		}
533
	
534
		/**
535
		 * @generated
536
		 */
537
		void valueChanged(UndoablePropertySheetEntry child, <%=importManager.getImportedName("org.eclipse.gef.commands.CompoundCommand")%> command) {
538
			<%=importManager.getImportedName("org.eclipse.gef.commands.CompoundCommand")%> cc = new <%=importManager.getImportedName("org.eclipse.gef.commands.CompoundCommand")%>();
539
			command.add(cc);
540
	
541
			SetValueCommand setCommand;
542
			for (int i = 0; i < getValues().length; i++) {
543
				setCommand = new SetValueCommand(child.getDisplayName());
544
				setCommand.setTarget(getPropertySource(getValues()[i]));
545
				setCommand.setPropertyId(child.getDescriptor().getId());
546
				setCommand.setPropertyValue(child.getValues()[i]);
547
				cc.add(setCommand);
548
			}
549
	
550
			// inform our parent
551
			if (getParent() != null)
552
				((UndoablePropertySheetEntry)getParent()).valueChanged(this, command);
553
			else {
554
				//I am the root entry
555
				stack.execute(command);
556
			}
557
		}
558
	}
559
560
	/**
200
	 * @generated
561
	 * @generated
201
	 */
562
	 */
202
	private EditingDomain editingDomain;
563
	private EditingDomain editingDomain;
Lines 521-527 Link Here
521
	protected PropertySheetPage getPropertySheetPage() {
882
	protected PropertySheetPage getPropertySheetPage() {
522
		if (undoablePropertySheetPage == null) {
883
		if (undoablePropertySheetPage == null) {
523
			undoablePropertySheetPage = new PropertySheetPage();
884
			undoablePropertySheetPage = new PropertySheetPage();
524
			<%=importManager.getImportedName("org.eclipse.gef.ui.properties.UndoablePropertySheetEntry")%> rootEntry = new <%=importManager.getImportedName("org.eclipse.gef.ui.properties.UndoablePropertySheetEntry")%>(getCommandStack());
885
			UndoablePropertySheetEntry rootEntry = new UndoablePropertySheetEntry(getCommandStack());
525
			rootEntry.setPropertySourceProvider(new <%=importManager.getImportedName(genDiagram.getPropertyProviderQualifiedClassName())%>(getDomainAdapterFactory()));
886
			rootEntry.setPropertySourceProvider(new <%=importManager.getImportedName(genDiagram.getPropertyProviderQualifiedClassName())%>(getDomainAdapterFactory()));
526
			undoablePropertySheetPage.setRootEntry(rootEntry);
887
			undoablePropertySheetPage.setRootEntry(rootEntry);
527
		}
888
		}

Return to bug 141743