| /******************************************************************************* |
| * Copyright (c) 2011, 2012 Red Hat, Inc. |
| * All rights reserved. |
| * This program is 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: |
| * Red Hat, Inc. - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.bpmn2.modeler.core.features; |
| |
| import org.eclipse.bpmn2.modeler.core.IConstants; |
| import org.eclipse.bpmn2.modeler.core.merrimac.dialogs.ObjectEditingDialog; |
| import org.eclipse.bpmn2.modeler.core.preferences.Bpmn2Preferences; |
| import org.eclipse.bpmn2.modeler.core.utils.BusinessObjectUtil; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.graphiti.features.IFeatureProvider; |
| import org.eclipse.graphiti.features.context.IContext; |
| import org.eclipse.graphiti.features.context.ICustomContext; |
| import org.eclipse.graphiti.features.custom.AbstractCustomFeature; |
| import org.eclipse.graphiti.mm.pictograms.PictogramElement; |
| import org.eclipse.graphiti.ui.editor.DiagramEditor; |
| import org.eclipse.jface.window.Window; |
| |
| /** |
| * The Class ShowPropertiesFeature. |
| */ |
| public class ShowPropertiesFeature extends AbstractCustomFeature { |
| |
| /** The changes done. */ |
| protected boolean changesDone = false; |
| |
| /** |
| * Instantiates a new show properties feature. |
| * |
| * @param fp the fp |
| */ |
| public ShowPropertiesFeature(IFeatureProvider fp) { |
| super(fp); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.graphiti.features.impl.AbstractFeature#getName() |
| */ |
| @Override |
| public String getName() { |
| return Messages.ShowPropertiesFeature_Name; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.graphiti.features.custom.AbstractCustomFeature#getDescription() |
| */ |
| @Override |
| public String getDescription() { |
| return Messages.ShowPropertiesFeature_Title; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.graphiti.features.custom.AbstractCustomFeature#canExecute(org.eclipse.graphiti.features.context.ICustomContext) |
| */ |
| @Override |
| public boolean canExecute(ICustomContext context) { |
| PictogramElement[] pes = context.getPictogramElements(); |
| EObject businessObject = BusinessObjectUtil.getBusinessObjectForPictogramElement(pes[0]); |
| if (pes.length==1) { |
| return Bpmn2Preferences.getInstance(businessObject).hasPopupConfigDialog(businessObject); |
| } |
| return false; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.graphiti.features.custom.AbstractCustomFeature#isAvailable(org.eclipse.graphiti.features.context.IContext) |
| */ |
| @Override |
| public boolean isAvailable(IContext context) { |
| return true; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.graphiti.features.custom.ICustomFeature#execute(org.eclipse.graphiti.features.context.ICustomContext) |
| */ |
| @Override |
| public void execute(ICustomContext context) { |
| PictogramElement[] pes = context.getPictogramElements(); |
| DiagramEditor editor = (DiagramEditor)getDiagramBehavior().getDiagramContainer(); |
| editor.setPictogramElementForSelection(pes[0]); |
| getDiagramBehavior().refresh(); |
| EObject businessObject = BusinessObjectUtil.getBusinessObjectForPictogramElement(pes[0]); |
| ObjectEditingDialog dialog = |
| new ObjectEditingDialog(editor, businessObject); |
| if (dialog.open() == Window.OK) |
| changesDone = dialog.hasDoneChanges(); |
| else |
| changesDone = false; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.graphiti.features.impl.AbstractFeature#hasDoneChanges() |
| */ |
| @Override |
| public boolean hasDoneChanges() { |
| return changesDone; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.graphiti.features.custom.AbstractCustomFeature#getImageId() |
| */ |
| @Override |
| public String getImageId() { |
| return IConstants.ICON_PROPERTIES_16; |
| } |
| |
| } |