david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2001, 2004 IBM Corporation and others. |
| 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | * which accompanies this distribution, and is available at |
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
| 7 | * |
| 8 | * Contributors: |
| 9 | * IBM Corporation - initial API and implementation |
| 10 | * Jens Lukowski/Innoopract - initial renaming/restructuring |
| 11 | * |
| 12 | *******************************************************************************/ |
nitind | 1bf20a1 | 2005-09-15 11:48:15 +0000 | [diff] [blame] | 13 | package org.eclipse.wst.dtd.ui.views.contentoutline; |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 14 | |
| 15 | import java.text.Collator; |
| 16 | |
| 17 | import org.eclipse.jface.preference.IPreferenceStore; |
| 18 | import org.eclipse.jface.viewers.TreeViewer; |
| 19 | import org.eclipse.jface.viewers.ViewerSorter; |
david_williams | 3804601 | 2005-04-08 19:04:29 +0000 | [diff] [blame] | 20 | import org.eclipse.wst.dtd.ui.internal.DTDUIMessages; |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 21 | import org.eclipse.wst.dtd.ui.internal.editor.DTDEditorPluginImageHelper; |
| 22 | import org.eclipse.wst.dtd.ui.internal.editor.DTDEditorPluginImages; |
nitind | bca2663 | 2005-03-30 18:13:32 +0000 | [diff] [blame] | 23 | import org.eclipse.wst.sse.ui.internal.contentoutline.PropertyChangeUpdateAction; |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 24 | |
nitind | 1bf20a1 | 2005-09-15 11:48:15 +0000 | [diff] [blame] | 25 | class SortAction extends PropertyChangeUpdateAction { |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 26 | private TreeViewer treeViewer; |
| 27 | |
| 28 | public SortAction(TreeViewer viewer, IPreferenceStore store, String preferenceKey) { |
david_williams | 3804601 | 2005-04-08 19:04:29 +0000 | [diff] [blame] | 29 | super(DTDUIMessages._UI_BUTTON_SORT_ITEMS, store, preferenceKey, false); //$NON-NLS-1$ |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 30 | setImageDescriptor(DTDEditorPluginImageHelper.getInstance().getImageDescriptor(DTDEditorPluginImages.IMG_OBJ_SORT)); |
| 31 | setToolTipText(getText()); |
| 32 | treeViewer = viewer; |
| 33 | if (isChecked()) { |
| 34 | treeViewer.setSorter(new ViewerSorter(Collator.getInstance())); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | /* |
| 39 | * (non-Javadoc) |
| 40 | * |
| 41 | * @see org.eclipse.ui.texteditor.IUpdate#update() |
| 42 | */ |
| 43 | public void update() { |
| 44 | super.update(); |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 45 | // treeViewer.getControl().setVisible(false); |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 46 | treeViewer.getControl().setRedraw(false); |
| 47 | Object[] expandedElements = treeViewer.getExpandedElements(); |
| 48 | if (isChecked()) { |
| 49 | treeViewer.setSorter(new ViewerSorter(Collator.getInstance())); |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 50 | } |
| 51 | else { |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 52 | treeViewer.setSorter(null); |
| 53 | } |
| 54 | treeViewer.setInput(treeViewer.getInput()); |
| 55 | treeViewer.setExpandedElements(expandedElements); |
| 56 | // treeViewer.getControl().setVisible(true); |
| 57 | treeViewer.getControl().setRedraw(true); |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 58 | } |
| 59 | } |