Source Code Cross Referenced for AddBookmarkAction.java in  » IDE-Eclipse » ui-ide » org » eclipse » ui » actions » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » ui ide » org.eclipse.ui.actions 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *        IBM Corporation - initial API and implementation 
010:         *   Sebastian Davids <sdavids@gmx.de>
011:         *     - Fix for bug 20510 - Add Bookmark action has wrong label in navigator or
012:         *       packages view
013:         *******************************************************************************/package org.eclipse.ui.actions;
014:
015:        import java.util.HashMap;
016:        import java.util.Iterator;
017:        import java.util.Map;
018:
019:        import org.eclipse.core.commands.ExecutionException;
020:        import org.eclipse.core.resources.IFile;
021:        import org.eclipse.core.resources.IMarker;
022:        import org.eclipse.core.resources.IResource;
023:        import org.eclipse.core.runtime.IAdaptable;
024:        import org.eclipse.jface.viewers.IStructuredSelection;
025:
026:        import org.eclipse.swt.widgets.Shell;
027:        import org.eclipse.ui.PlatformUI;
028:        import org.eclipse.ui.ide.undo.CreateMarkersOperation;
029:        import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
030:        import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
031:        import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
032:        import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
033:        import org.eclipse.ui.internal.views.bookmarkexplorer.BookmarkMessages;
034:        import org.eclipse.ui.views.bookmarkexplorer.BookmarkPropertiesDialog;
035:
036:        /**
037:         * Standard action for adding a bookmark to the currently selected file
038:         * resource(s).
039:         * <p>
040:         * This class may be instantiated; it is not intended to be subclassed.
041:         * </p>
042:         */
043:        public class AddBookmarkAction extends SelectionListenerAction {
044:
045:            /**
046:             * The id of this action.
047:             */
048:            public static final String ID = PlatformUI.PLUGIN_ID
049:                    + ".AddBookmarkAction"; //$NON-NLS-1$
050:
051:            /**
052:             * The shell in which to show any dialogs.
053:             */
054:            private Shell shell;
055:
056:            /**
057:             * Whether to prompt the user for the bookmark name.
058:             */
059:            private boolean promptForName = true;
060:
061:            /**
062:             * Creates a new bookmark action. By default, prompts the user for the
063:             * bookmark name.
064:             * 
065:             * @param shell
066:             *            the shell for any dialogs
067:             */
068:            public AddBookmarkAction(Shell shell) {
069:                this (shell, true);
070:            }
071:
072:            /**
073:             * Creates a new bookmark action.
074:             * 
075:             * @param shell
076:             *            the shell for any dialogs
077:             * @param promptForName
078:             *            whether to ask the user for the bookmark name
079:             */
080:            public AddBookmarkAction(Shell shell, boolean promptForName) {
081:                super (IDEWorkbenchMessages.AddBookmarkLabel);
082:                setId(ID);
083:                if (shell == null) {
084:                    throw new IllegalArgumentException();
085:                }
086:                this .shell = shell;
087:                this .promptForName = promptForName;
088:                setToolTipText(IDEWorkbenchMessages.AddBookmarkToolTip);
089:                PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
090:                        IIDEHelpContextIds.ADD_BOOKMARK_ACTION);
091:            }
092:
093:            /*
094:             * (non-Javadoc) Method declared on IAction.
095:             */
096:            public void run() {
097:                IStructuredSelection selection = getStructuredSelection();
098:                for (Iterator i = selection.iterator(); i.hasNext();) {
099:                    Object o = i.next();
100:                    IFile file = null;
101:                    if (o instanceof  IFile) {
102:                        file = (IFile) o;
103:                    } else if (o instanceof  IAdaptable) {
104:                        Object resource = ((IAdaptable) o)
105:                                .getAdapter(IResource.class);
106:                        if (resource instanceof  IFile) {
107:                            file = (IFile) resource;
108:                        }
109:                    }
110:                    if (file != null) {
111:                        if (promptForName) {
112:                            BookmarkPropertiesDialog dialog = new BookmarkPropertiesDialog(
113:                                    shell);
114:                            dialog.setResource(file);
115:                            dialog.open();
116:                        } else {
117:                            Map attrs = new HashMap();
118:                            attrs.put(IMarker.MESSAGE, file.getName());
119:                            CreateMarkersOperation op = new CreateMarkersOperation(
120:                                    IMarker.BOOKMARK, attrs, file,
121:                                    BookmarkMessages.CreateBookmark_undoText);
122:                            try {
123:                                PlatformUI
124:                                        .getWorkbench()
125:                                        .getOperationSupport()
126:                                        .getOperationHistory()
127:                                        .execute(
128:                                                op,
129:                                                null,
130:                                                WorkspaceUndoUtil
131:                                                        .getUIInfoAdapter(shell));
132:                            } catch (ExecutionException e) {
133:                                IDEWorkbenchPlugin.log(null, e); // We don't care
134:                            }
135:                        }
136:                    }
137:                }
138:
139:            }
140:
141:            /**
142:             * The <code>AddBookmarkAction</code> implementation of this
143:             * <code>SelectionListenerAction</code> method enables the action only if
144:             * the selection is not empty and contains just file resources.
145:             */
146:            protected boolean updateSelection(IStructuredSelection selection) {
147:                // @issue typed selections
148:                return super.updateSelection(selection) && !selection.isEmpty()
149:                        && selectionIsOfType(IResource.FILE);
150:            }
151:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.