Java tutorial
/* license-start * * Copyright (C) 2008 - 2013 Crispico, <http://www.crispico.com/>. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation version 3. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details, at <http://www.gnu.org/licenses/>. * * Contributors: * Crispico - Initial API and implementation * * license-end */ package com.crispico.flower.mp.contributions; import java.util.List; import org.eclipse.emf.edit.domain.EditingDomain; import org.eclipse.emf.edit.ui.action.RedoAction; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; import com.crispico.flower.mp.FlowerMPUtils; import com.crispico.flower.mp.RelationVirtualElement; public class FlowerRedoAction extends EditingDomainFlowerAction { private static final String EDIT_GROUP = "group.edit"; protected RedoAction redoAction = new RedoAction(); public void setEditingDomain(EditingDomain domain) { redoAction.setEditingDomain(domain); } public void setEnabled(boolean enabled) { redoAction.setEnabled(enabled); } /** * @flowerModelElementId _NN43Yr_SEd-259cbnb9fYw */ public FlowerRedoAction() { label = redoAction.getText(); image = "action/redo_edit.gif"; group = EDIT_GROUP; } /** * @flowerModelElementId _0dnXgNXREd-4l6LZuYEfyA */ @Override public boolean isVisible(List<?> selection) { return true; } /** * @flowerModelElementId _0dn-ktXREd-4l6LZuYEfyA */ @Override public boolean isEnabled(List<?> selection) { update(new StructuredSelection(selection)); return redoAction.isEnabled(); } /** * @flowerModelElementId _0dolotXREd-4l6LZuYEfyA */ @Override public void run(List<?> selection) { update(new StructuredSelection(selection)); redoAction.run(); } /** * Update editing domain from selection */ public void update(IStructuredSelection selection) { // get editing domain EditingDomain editingDomain = FlowerMPUtils.getEditingDomainFromSelection(selection.toList()); // if editingDomain not null, update action if (editingDomain != null) { setEditingDomain(editingDomain); update(); } else { // editingDomain is null, reset action setEnabled(false); // check to see if we have Relations elements inside the selection boolean containsVirtualElements = false; for (Object obj : selection.toList()) { if (obj instanceof RelationVirtualElement) { containsVirtualElements = true; break; } } if (containsVirtualElements) { IStructuredSelection newSelection = replaceVirtualElements(selection); // get the editingDomain from new selection EditingDomain domain = FlowerMPUtils.getEditingDomainFromSelection(selection.toList()); // update only if the found domain is not null if (domain != null) { setEditingDomain(domain); update(); } } } } public void update() { redoAction.update(); label = redoAction.getText(); } }