]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.workbench/src/org/simantics/workbench/internal/contributions/search/SearchTrim.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.workbench / src / org / simantics / workbench / internal / contributions / search / SearchTrim.java
index a0c2d5593487f8f7f2b8ae2ba7eef0b2259e670f..069e31a07a5f64c3c0a0d716e107ce96c6f759fe 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.workbench.internal.contributions.search;\r
-\r
-import org.eclipse.jface.layout.GridDataFactory;\r
-import org.eclipse.jface.layout.GridLayoutFactory;\r
-import org.eclipse.jface.resource.JFaceResources;\r
-import org.eclipse.jface.resource.LocalResourceManager;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.events.DisposeEvent;\r
-import org.eclipse.swt.events.DisposeListener;\r
-import org.eclipse.swt.events.KeyAdapter;\r
-import org.eclipse.swt.events.KeyEvent;\r
-import org.eclipse.swt.graphics.Image;\r
-import org.eclipse.swt.layout.GridData;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.swt.widgets.Shell;\r
-import org.eclipse.swt.widgets.Text;\r
-import org.eclipse.ui.PlatformUI;\r
-import org.eclipse.ui.swt.IFocusService;\r
-import org.simantics.utils.ui.BundleUtils;\r
-import org.simantics.workbench.search.ISearchService;\r
-import org.simantics.workbench.search.SearchQuery;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class SearchTrim extends Composite {\r
-\r
-    private static final String SEARCH_TEXT_FOCUS_CONTROL_ID = "org.simantics.workbench.search.text";\r
-\r
-       \r
-\r
-    public static final String         KEY_TRIM    = "SearchTrim";\r
-\r
-   \r
-\r
-    private final LocalResourceManager resourceManager;\r
-\r
-    private final boolean              disabled    = false;\r
-\r
-    protected final Text                 searchText;\r
-\r
-    /**\r
-     * Creates a new heap status control with the given parent, and using the\r
-     * given preference store to obtain settings such as the refresh interval.\r
-     * \r
-     * @param parent the parent composite\r
-     * @param prefStore the preference store\r
-     */\r
-    public SearchTrim(Composite parent) {\r
-        super(parent, SWT.NONE);\r
-\r
-        // System.err.println("parent: " + parent.getLayout());\r
-        this.resourceManager = new LocalResourceManager(JFaceResources.getResources(), this);\r
-\r
-        searchText = new Text(this, SWT.BORDER | SWT.FLAT | SWT.SEARCH | SWT.ICON_SEARCH);\r
-        searchText.setToolTipText("Enter Search Criteria for Active Model");\r
-        GridDataFactory.fillDefaults().hint(100, SWT.DEFAULT).grab(true, true).applyTo(searchText);\r
-        searchText.addKeyListener(new KeyAdapter() {\r
-            @Override\r
-            public void keyPressed(KeyEvent e) {\r
-                if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {\r
-                    nameAndTypeQuery(((e.stateMask & SWT.CTRL) == 0) ? ISearchService.ResultBrowser.VIEW : ISearchService.ResultBrowser.EDITOR);\r
-                }\r
-            }\r
-        });\r
-\r
-        if (PlatformUI.isWorkbenchRunning()) {\r
-            IFocusService service = (IFocusService) PlatformUI.getWorkbench().getService(IFocusService.class);\r
-            service.addFocusTracker(searchText, SEARCH_TEXT_FOCUS_CONTROL_ID);\r
-        }\r
-\r
-        if ((searchText.getStyle() & SWT.ICON_SEARCH) == 0) {\r
-            final Label searchButton= new Label(this, SWT.NONE);\r
-            searchButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, true));\r
-            searchButton.setImage((Image) resourceManager.get(BundleUtils.getImageDescriptorFromPlugin("com.famfamfam.silk", "/icons/magnifier.png")));\r
-            searchButton.moveAbove(searchText);\r
-            searchButton.setToolTipText("Search Active Model Contents");\r
-\r
-            GridLayoutFactory.swtDefaults().margins(0, 0).spacing(0, 0).numColumns(3).applyTo(this);\r
-        } else {\r
-            GridLayoutFactory.swtDefaults().margins(0, 0).spacing(0, 0).numColumns(2).applyTo(this);\r
-        }\r
-\r
-        Label filler = new Label(this, SWT.NONE);\r
-        GridDataFactory.swtDefaults().grab(true, false).minSize(3, SWT.DEFAULT).applyTo(filler);\r
-\r
-        /*\r
-\r
-        final Button b = new Button(this, SWT.PUSH);\r
-        // b.setText("Search by Name");\r
-        b.setText("&Name");\r
-        b.setToolTipText("Search by Name");\r
-        b.setImage(resourceManager.createImage(Activator.getImageDescriptor("img/magnifier.png")));\r
-        GridDataFactory.fillDefaults().applyTo(b);\r
-        b.addSelectionListener(new SelectionAdapter() {\r
-            @Override\r
-            public void widgetSelected(SelectionEvent e) {\r
-                nameQuery(((e.stateMask & SWT.CTRL) == 0) ? ResultBrowser.VIEW : ResultBrowser.EDITOR);\r
-            }\r
-        });\r
-\r
-        final Button b2 = new Button(this, SWT.PUSH);\r
-        b2.setText("&Type");\r
-        // b2.setText("Search by Type");\r
-        b2.setToolTipText("Search by Type");\r
-        GridDataFactory.fillDefaults().applyTo(b2);\r
-\r
-        b2.setImage(resourceManager.createImage(Activator.getImageDescriptor("img/magnifier.png")));\r
-        b2.addSelectionListener(new SelectionAdapter() {\r
-            @Override\r
-            public void widgetSelected(SelectionEvent e) {\r
-                typeQuery(((e.stateMask & SWT.CTRL) == 0) ? ResultBrowser.VIEW : ResultBrowser.EDITOR);\r
-            }\r
-        });\r
-        */\r
-\r
-        // Register the KEY_TRIM datum into this controls parent Shell.\r
-        // This enables FocusSearchTrim handler to work (to focus this control).\r
-        final Shell shell = parent.getShell();\r
-        shell.setData(KEY_TRIM, searchText);\r
-        addDisposeListener(new DisposeListener() {\r
-            @Override\r
-            public void widgetDisposed(DisposeEvent e) {\r
-                shell.setData(KEY_TRIM, null);\r
-            }\r
-        });\r
-    }\r
-\r
-    protected void nameQuery(ISearchService.ResultBrowser browserType) {\r
-        if (disabled)\r
-            return;\r
-        String originalInput = searchText.getText();\r
-        String query = originalInput;\r
-\r
-        // Don't allow empty queries\r
-        if (query.trim().isEmpty())\r
-            return;\r
-\r
-        query = filter(query);\r
-\r
-        SearchQuery searchQuery = new SearchQuery(originalInput);\r
-        searchQuery.setSearchFlag("Name", "on");\r
-        performQuery(searchQuery, browserType);\r
-    }\r
-\r
-    protected void typeQuery(ISearchService.ResultBrowser browserType) {\r
-        if (disabled)\r
-            return;\r
-        String originalInput = searchText.getText();\r
-        String query = originalInput;\r
-\r
-        // Don't allow empty queries\r
-        if (query.trim().isEmpty())\r
-            return;\r
-        \r
-        SearchQuery searchQuery = new SearchQuery(originalInput);\r
-        searchQuery.setSearchFlag("Types", "on");\r
-        performQuery(searchQuery, browserType);\r
-    }\r
-\r
-    protected void nameAndTypeQuery(ISearchService.ResultBrowser browserType) {\r
-        if (disabled)\r
-            return;\r
-        String originalInput = searchText.getText();\r
-        String query = originalInput;\r
-\r
-        // Don't allow empty queries\r
-        if (query.trim().isEmpty())\r
-            return;\r
-\r
-        SearchQuery searchQuery = new SearchQuery(originalInput);\r
-        searchQuery.setSearchFlag("Name", "on");\r
-        searchQuery.setSearchFlag("Types", "on");\r
-        performQuery(searchQuery, browserType);\r
-    }\r
-\r
-    protected String filter(String query) {\r
-        // TODO: implement\r
-        if (!query.endsWith("*"))\r
-            query += "*";\r
-        // ''' characters cannot be used in the query string, replace them with '"'\r
-        query = query.replaceAll("'", "\"");\r
-        return query;\r
-    }\r
-\r
-    protected void performQuery(SearchQuery query, ISearchService.ResultBrowser browserType) {\r
-       ISearchService searchService = (ISearchService)PlatformUI.getWorkbench().getService(ISearchService.class);\r
-       searchService.performQuery(query, browserType, true);\r
-    }\r
-\r
-   \r
-    \r
-\r
-\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * 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:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.workbench.internal.contributions.search;
+
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.swt.IFocusService;
+import org.simantics.utils.ui.BundleUtils;
+import org.simantics.workbench.search.ISearchService;
+import org.simantics.workbench.search.SearchQuery;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class SearchTrim extends Composite {
+
+    private static final String SEARCH_TEXT_FOCUS_CONTROL_ID = "org.simantics.workbench.search.text";
+
+       
+
+    public static final String         KEY_TRIM    = "SearchTrim";
+
+   
+
+    private final LocalResourceManager resourceManager;
+
+    private final boolean              disabled    = false;
+
+    protected final Text                 searchText;
+
+    /**
+     * Creates a new heap status control with the given parent, and using the
+     * given preference store to obtain settings such as the refresh interval.
+     * 
+     * @param parent the parent composite
+     * @param prefStore the preference store
+     */
+    public SearchTrim(Composite parent) {
+        super(parent, SWT.NONE);
+
+        // System.err.println("parent: " + parent.getLayout());
+        this.resourceManager = new LocalResourceManager(JFaceResources.getResources(), this);
+
+        searchText = new Text(this, SWT.BORDER | SWT.FLAT | SWT.SEARCH | SWT.ICON_SEARCH);
+        searchText.setToolTipText("Enter Search Criteria for Active Model");
+        GridDataFactory.fillDefaults().hint(100, SWT.DEFAULT).grab(true, true).applyTo(searchText);
+        searchText.addKeyListener(new KeyAdapter() {
+            @Override
+            public void keyPressed(KeyEvent e) {
+                if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
+                    nameAndTypeQuery(((e.stateMask & SWT.CTRL) == 0) ? ISearchService.ResultBrowser.VIEW : ISearchService.ResultBrowser.EDITOR);
+                }
+            }
+        });
+
+        if (PlatformUI.isWorkbenchRunning()) {
+            IFocusService service = (IFocusService) PlatformUI.getWorkbench().getService(IFocusService.class);
+            service.addFocusTracker(searchText, SEARCH_TEXT_FOCUS_CONTROL_ID);
+        }
+
+        if ((searchText.getStyle() & SWT.ICON_SEARCH) == 0) {
+            final Label searchButton= new Label(this, SWT.NONE);
+            searchButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, true));
+            searchButton.setImage((Image) resourceManager.get(BundleUtils.getImageDescriptorFromPlugin("com.famfamfam.silk", "/icons/magnifier.png")));
+            searchButton.moveAbove(searchText);
+            searchButton.setToolTipText("Search Active Model Contents");
+
+            GridLayoutFactory.swtDefaults().margins(0, 0).spacing(0, 0).numColumns(3).applyTo(this);
+        } else {
+            GridLayoutFactory.swtDefaults().margins(0, 0).spacing(0, 0).numColumns(2).applyTo(this);
+        }
+
+        Label filler = new Label(this, SWT.NONE);
+        GridDataFactory.swtDefaults().grab(true, false).minSize(3, SWT.DEFAULT).applyTo(filler);
+
+        /*
+
+        final Button b = new Button(this, SWT.PUSH);
+        // b.setText("Search by Name");
+        b.setText("&Name");
+        b.setToolTipText("Search by Name");
+        b.setImage(resourceManager.createImage(Activator.getImageDescriptor("img/magnifier.png")));
+        GridDataFactory.fillDefaults().applyTo(b);
+        b.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                nameQuery(((e.stateMask & SWT.CTRL) == 0) ? ResultBrowser.VIEW : ResultBrowser.EDITOR);
+            }
+        });
+
+        final Button b2 = new Button(this, SWT.PUSH);
+        b2.setText("&Type");
+        // b2.setText("Search by Type");
+        b2.setToolTipText("Search by Type");
+        GridDataFactory.fillDefaults().applyTo(b2);
+
+        b2.setImage(resourceManager.createImage(Activator.getImageDescriptor("img/magnifier.png")));
+        b2.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                typeQuery(((e.stateMask & SWT.CTRL) == 0) ? ResultBrowser.VIEW : ResultBrowser.EDITOR);
+            }
+        });
+        */
+
+        // Register the KEY_TRIM datum into this controls parent Shell.
+        // This enables FocusSearchTrim handler to work (to focus this control).
+        final Shell shell = parent.getShell();
+        shell.setData(KEY_TRIM, searchText);
+        addDisposeListener(new DisposeListener() {
+            @Override
+            public void widgetDisposed(DisposeEvent e) {
+                shell.setData(KEY_TRIM, null);
+            }
+        });
+    }
+
+    protected void nameQuery(ISearchService.ResultBrowser browserType) {
+        if (disabled)
+            return;
+        String originalInput = searchText.getText();
+        String query = originalInput;
+
+        // Don't allow empty queries
+        if (query.trim().isEmpty())
+            return;
+
+        query = filter(query);
+
+        SearchQuery searchQuery = new SearchQuery(originalInput);
+        searchQuery.setSearchFlag("Name", "on");
+        performQuery(searchQuery, browserType);
+    }
+
+    protected void typeQuery(ISearchService.ResultBrowser browserType) {
+        if (disabled)
+            return;
+        String originalInput = searchText.getText();
+        String query = originalInput;
+
+        // Don't allow empty queries
+        if (query.trim().isEmpty())
+            return;
+        
+        SearchQuery searchQuery = new SearchQuery(originalInput);
+        searchQuery.setSearchFlag("Types", "on");
+        performQuery(searchQuery, browserType);
+    }
+
+    protected void nameAndTypeQuery(ISearchService.ResultBrowser browserType) {
+        if (disabled)
+            return;
+        String originalInput = searchText.getText();
+        String query = originalInput;
+
+        // Don't allow empty queries
+        if (query.trim().isEmpty())
+            return;
+
+        SearchQuery searchQuery = new SearchQuery(originalInput);
+        searchQuery.setSearchFlag("Name", "on");
+        searchQuery.setSearchFlag("Types", "on");
+        performQuery(searchQuery, browserType);
+    }
+
+    protected String filter(String query) {
+        // TODO: implement
+        if (!query.endsWith("*"))
+            query += "*";
+        // ''' characters cannot be used in the query string, replace them with '"'
+        query = query.replaceAll("'", "\"");
+        return query;
+    }
+
+    protected void performQuery(SearchQuery query, ISearchService.ResultBrowser browserType) {
+       ISearchService searchService = (ISearchService)PlatformUI.getWorkbench().getService(ISearchService.class);
+       searchService.performQuery(query, browserType, true);
+    }
+
+   
+    
+
+
 }
\ No newline at end of file