/******************************************************************************* | |
* Copyright (c) 2004-2008 Istvan Rath and Daniel Varro | |
* 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: | |
* Istvan Rath - initial API and implementation | |
*******************************************************************************/ | |
package org.eclipse.viatra2.treeeditor.properties; | |
import org.eclipse.jface.viewers.ISelection; | |
import org.eclipse.jface.viewers.IStructuredSelection; | |
import org.eclipse.swt.widgets.Tree; | |
import org.eclipse.swt.widgets.TreeItem; | |
import org.eclipse.ui.IWorkbenchPart; | |
import org.eclipse.ui.views.properties.IPropertySheetEntry; | |
import org.eclipse.ui.views.properties.IPropertySource; | |
import org.eclipse.ui.views.properties.IPropertySourceProvider; | |
import org.eclipse.ui.views.properties.PropertySheetPage; | |
import org.eclipse.ui.views.properties.PropertySheetSorter; | |
import org.eclipse.viatra2.core.ICoreNotificationListener; | |
import org.eclipse.viatra2.core.IModelElement; | |
import org.eclipse.viatra2.core.notification.ICoreNotificationObject; | |
import org.eclipse.viatra2.treeeditor.ViatraTreeEditor; | |
import org.eclipse.viatra2.treeeditor.properties.util.LabelTranslator; | |
/** | |
* Property sheet page to display VPM properties organized into dynamic categories. | |
* | |
* Supports: | |
* - Core Nofitication listener to track changes occurring to currently selected elements | |
* - support for editor actions (undo, redo, delete) | |
* | |
* @author istvan rath | |
* | |
*/ | |
public class VPMPropertySheetPage extends PropertySheetPage | |
implements ICoreNotificationListener | |
{ | |
ViatraTreeEditor iEditor; | |
/** | |
* Reference to the currently displayed element. | |
*/ | |
IModelElement iElement; | |
/** | |
* Customized sorter to ensure proper ordering in the properties view. | |
*/ | |
VPMPropsSorter iSorter = new VPMPropsSorter(); | |
protected class VPMPropsSorter extends PropertySheetSorter | |
{ | |
@Override | |
public int compare(IPropertySheetEntry entryA, | |
IPropertySheetEntry entryB) | |
{ | |
VPMProperties p1 = LabelTranslator.getVPMProperty(entryA.getDisplayName()); | |
VPMProperties p2 = LabelTranslator.getVPMProperty(entryB.getDisplayName()); | |
//return super.compare(entryA, entryB); | |
return p1.compareTo(p2); | |
} | |
/** | |
* Order of categories: (comes from VPMPropertyCategory.java) | |
* 1) NAMING AND VALUES (name, fqn, value, viewinfo) | |
* 2) TYPES AND SUPERTYPES (type, instance, supertype, subtype, isFinalType) | |
* 3) SOURCE/TARGET (src,trg,isAggregation,multiplicity,-inverse) | |
*/ | |
@Override | |
public int compareCategories(String categoryA, String categoryB) | |
{ | |
VPMPropertyCategory c1 = LabelTranslator.getPropCategory(categoryA); | |
VPMPropertyCategory c2 = LabelTranslator.getPropCategory(categoryB); | |
//return super.compareCategories(categoryA, categoryB); | |
return c1.compareTo(c2); | |
} | |
} | |
public VPMPropertySheetPage(ViatraTreeEditor e) | |
{ | |
iEditor = e; | |
// set up the properties page | |
setSorter(iSorter); | |
setPropertySourceProvider(new IPropertySourceProvider(){ | |
public IPropertySource getPropertySource(Object object) { | |
if (object instanceof IModelElement) | |
return new VPMPropertySource((IModelElement)object,iEditor); | |
return null; | |
} | |
}); | |
} | |
@Override | |
public void selectionChanged(IWorkbenchPart part, ISelection selection) | |
{ | |
super.selectionChanged(part, selection); | |
// remove previous attachment | |
if (iElement!=null) | |
{ | |
iElement.getModelSpace().getNotificationManager().removeNotificationListener(iElement,this); | |
} | |
if (selection instanceof IStructuredSelection) | |
{ | |
Object o = ((IStructuredSelection)selection).getFirstElement(); | |
if (o instanceof IModelElement) | |
iElement = (IModelElement)o; | |
} | |
} | |
/** | |
* Retain expanded state. | |
*/ | |
@Override | |
public void refresh() { | |
//super.refresh(); | |
TreeItem[] is = ((Tree)getControl()).getSelection(); | |
super.refresh(); | |
((Tree)this.getControl()).setSelection(is); | |
((Tree)this.getControl()).showSelection(); | |
} | |
public void actionPerformed(ICoreNotificationObject notification) | |
{ | |
this.refresh(); | |
} | |
public int getListenerCategory() { return 0; } | |
} |