]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/symbollibrary/ui/ActivateFilterHandler.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / symbollibrary / ui / ActivateFilterHandler.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.diagram.symbollibrary.ui;
13
14 import org.eclipse.core.commands.AbstractHandler;
15 import org.eclipse.core.commands.ExecutionEvent;
16 import org.eclipse.core.commands.ExecutionException;
17 import org.eclipse.swt.widgets.Control;
18 import org.eclipse.ui.IWorkbenchPart;
19 import org.eclipse.ui.handlers.HandlerUtil;
20 import org.eclipse.ui.part.IPage;
21 import org.eclipse.ui.part.PageBookView;
22
23 /**
24  * @author Tuukka Lehtonen
25  */
26 public class ActivateFilterHandler extends AbstractHandler {
27
28     FilterArea getFilterArea(IWorkbenchPart part) {
29         if (part instanceof SymbolLibraryView) {
30             SymbolLibraryView slv = (SymbolLibraryView) part;
31             return slv.getFilterArea();
32         }
33         if (part instanceof SymbolPageView) {
34             PageBookView pv = (PageBookView) part;
35             IPage page = pv.getCurrentPage();
36             Control ctrl = page.getControl();
37             if (ctrl instanceof SymbolLibraryComposite) {
38                 return ((SymbolLibraryComposite) ctrl).getFilterArea();
39             }
40         }
41         return null;
42     }
43
44     @Override
45     public Object execute(ExecutionEvent event) throws ExecutionException {
46         IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
47         FilterArea filter = getFilterArea(part);
48         if (filter != null && !filter.isDisposed())
49             filter.focus();
50         return null;
51     }
52
53 }