Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: eb4523b239a94a20e614be5c70ba1e94830ae2b3 (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
/*******************************************************************************
 * <copyright>
 *
 * Copyright (c) 2005, 2010 SAP AG.
 * 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:
 *    Stefan Dimov - initial API, implementation and documentation
 *
 * </copyright>
 *
 *******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature;

import java.util.Iterator;

import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.ICustomContext;
import org.eclipse.graphiti.features.context.impl.CustomContext;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.mm.pictograms.Shape;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
import org.eclipse.swt.widgets.Display;


public class DiscardAndRemoveAllEntitiesFeature extends RemoveAllEntitiesFeature {

	public DiscardAndRemoveAllEntitiesFeature(IFeatureProvider fp) {
		super(fp);
	}
	
	@Override
	public String getConfirmationText() {
		return JPAEditorMessages.JPAEditorToolBehaviorProvider_removeAndDiscardAllEntitiesConfirmation;
	}
	
	@Override
	public void execute(ICustomContext context) {
		MessageDialog dlg = new MessageDialog(Display.getCurrent().getShells()[0], 
												JPAEditorMessages.JPAEditorToolBehaviorProvider_removeAllEntitiesMenu, 
												null, getConfirmationText(), 0, 
												new String[] {JPAEditorMessages.BTN_OK, JPAEditorMessages.BTN_CANCEL}, Dialog.CANCEL);
		if (dlg.open() != Dialog.OK)
			return;		
		Iterator<Shape> it = this.getDiagram().getChildren().iterator();
		while (it.hasNext()) {
			Shape sh = it.next();
			RestoreEntityFeature ft = new RestoreEntityFeature(getFeatureProvider());
			ICustomContext ctx = new CustomContext(new PictogramElement[] { sh });
			ft.execute(ctx);
			allShapes.add(sh);
		}
		super.execute(context);
	}		
	
	@Override
	public String getName() {
		return JPAEditorMessages.DiscardAndRemoveAllEntitiesFeature_ContextMenuOperationDescription;
		
	}

}

Back to the top