2 * Copyright (c) 2003-2004 Christopher Lenz and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * Christopher Lenz - initial API and implementation
11 * $Id: CssOutlineDoubleClickListener.java,v 1.1 2004-09-02 18:11:49 jsurfer Exp $
14 package net.sourceforge.phpeclipse.css.ui.internal.outline;
16 import net.sourceforge.phpeclipse.css.core.model.IStyleRule;
17 import net.sourceforge.phpeclipse.css.ui.CssUI;
19 import org.eclipse.jface.viewers.DoubleClickEvent;
20 import org.eclipse.jface.viewers.IDoubleClickListener;
21 import org.eclipse.jface.viewers.ISelection;
22 import org.eclipse.jface.viewers.IStructuredSelection;
23 import org.eclipse.ui.IPageLayout;
24 import org.eclipse.ui.IWorkbenchPage;
25 import org.eclipse.ui.PartInitException;
26 import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
29 * A double click listener that is intended to be attached to an outline page
30 * displaying CSS elements. If a style rule is double clicked, it will attempt
31 * to show the standard properties view.
33 public class CssOutlineDoubleClickListener implements IDoubleClickListener {
35 // Instance Variables ------------------------------------------------------
38 * The associated content outline page.
40 private ContentOutlinePage outlinePage;
42 // Constructors ------------------------------------------------------------
47 * @param outlinePage the associated outline page
49 public CssOutlineDoubleClickListener(ContentOutlinePage outlinePage) {
50 this.outlinePage = outlinePage;
53 // IDoubleClickListener Implementation -------------------------------------
56 * @see IDoubleClickListener#doubleClick(DoubleClickEvent)
58 public void doubleClick(DoubleClickEvent event) {
59 Object selectedElement = getSelectedElement(event.getSelection());
60 if (selectedElement instanceof IStyleRule) {
65 // Private Methods ---------------------------------------------------------
68 * Shows the properties view in the current workbench window.
70 private void showPropertiesView() {
71 IWorkbenchPage workbenchPage = outlinePage.getSite().getPage();
73 workbenchPage.showView(IPageLayout.ID_PROP_SHEET);
74 } catch (PartInitException e) {
76 "Could not show properties view", e); //$NON-NLS-1$
81 * Finds the element that is selected. As this is a double click listener,
82 * only a single element can be selected at once.
84 * @param selection the selection
85 * @return the selected element
87 private Object getSelectedElement(ISelection selection) {
88 Object element = null;
89 if (selection instanceof IStructuredSelection) {
90 element = ((IStructuredSelection) selection).getFirstElement();