| /******************************************************************************* |
| * Copyright (c) 2006 IBM Corporation and others. |
| * 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: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.ui.examples.views.properties.tabbed.logic.properties; |
| |
| import java.beans.PropertyChangeEvent; |
| import java.beans.PropertyChangeListener; |
| |
| import org.eclipse.gef.EditPart; |
| import org.eclipse.gef.examples.logicdesigner.model.LogicElement; |
| import org.eclipse.jface.util.Assert; |
| import org.eclipse.jface.viewers.ISelection; |
| import org.eclipse.jface.viewers.IStructuredSelection; |
| import org.eclipse.ui.IWorkbenchPart; |
| import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection; |
| |
| /** |
| * Abstract class for a section in a tab in the properties view. |
| * |
| * @author Anthony Hunter |
| */ |
| public abstract class AbstractSection |
| extends AbstractPropertySection implements PropertyChangeListener { |
| |
| private LogicElement element; |
| |
| /** |
| * @see org.eclipse.ui.views.properties.tabbed.ITabbedPropertySection#setInput(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) |
| */ |
| public void setInput(IWorkbenchPart part, ISelection selection) { |
| super.setInput(part, selection); |
| Assert.isTrue(selection instanceof IStructuredSelection); |
| Object input = ((IStructuredSelection)selection).getFirstElement(); |
| Assert.isTrue(input instanceof EditPart); |
| Object model = ((EditPart) input).getModel(); |
| Assert.isTrue(model instanceof LogicElement); |
| this.element = (LogicElement) model; |
| } |
| |
| /** |
| * @see org.eclipse.ui.views.properties.tabbed.view.ITabbedPropertySection#aboutToBeShown() |
| */ |
| public void aboutToBeShown() { |
| getElement().addPropertyChangeListener(this); |
| } |
| |
| /** |
| * @see org.eclipse.ui.views.properties.tabbed.view.ITabbedPropertySection#aboutToBeHidden() |
| */ |
| public void aboutToBeHidden() { |
| getElement().removePropertyChangeListener(this); |
| } |
| |
| /** |
| * Get the element. |
| * @return the element. |
| */ |
| public LogicElement getElement() { |
| return element; |
| } |
| |
| /** |
| * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) |
| */ |
| public void propertyChange(PropertyChangeEvent evt) { |
| refresh(); |
| } |
| } |