Source Code Cross Referenced for ActionPasteMarker.java in  » IDE-Eclipse » ui-ide » org » eclipse » ui » views » markers » internal » 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.views.markers.internal 
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:         *******************************************************************************/package org.eclipse.ui.views.markers.internal;
011:
012:        import java.util.ArrayList;
013:        import java.util.Map;
014:
015:        import org.eclipse.core.resources.IMarker;
016:        import org.eclipse.core.resources.IResource;
017:        import org.eclipse.core.resources.IWorkspaceRunnable;
018:        import org.eclipse.core.resources.ResourcesPlugin;
019:        import org.eclipse.core.runtime.CoreException;
020:        import org.eclipse.core.runtime.IProgressMonitor;
021:        import org.eclipse.jface.dialogs.ErrorDialog;
022:        import org.eclipse.jface.viewers.ISelectionProvider;
023:        import org.eclipse.jface.viewers.StructuredSelection;
024:        import org.eclipse.osgi.util.NLS;
025:        import org.eclipse.swt.dnd.Clipboard;
026:        import org.eclipse.ui.ISharedImages;
027:        import org.eclipse.ui.IWorkbenchPart;
028:        import org.eclipse.ui.PlatformUI;
029:        import org.eclipse.ui.ide.undo.CreateMarkersOperation;
030:        import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
031:        import org.eclipse.ui.part.MarkerTransfer;
032:
033:        /**
034:         * Pastes one or more bookmark(s) from the clipboard into the bookmark
035:         * navigator.
036:         */
037:        public class ActionPasteMarker extends MarkerSelectionProviderAction {
038:
039:            private IWorkbenchPart part;
040:
041:            private Clipboard clipboard;
042:
043:            private String[] pastableTypes;
044:
045:            private String markerName;
046:
047:            /**
048:             * Creates the action.
049:             * 
050:             * @param part
051:             * @param provider
052:             * @param markerName
053:             *            the name used to describe the specific kind of marker being
054:             *            pasted.
055:             */
056:            public ActionPasteMarker(IWorkbenchPart part,
057:                    ISelectionProvider provider, String markerName) {
058:                super (provider, MarkerMessages.pasteAction_title);
059:                this .part = part;
060:                this .pastableTypes = new String[0];
061:                this .markerName = markerName;
062:                setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
063:                        .getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
064:                setEnabled(false);
065:            }
066:
067:            void setClipboard(Clipboard clipboard) {
068:                this .clipboard = clipboard;
069:            }
070:
071:            /**
072:             * Copies the marker(s) from the clipboard to the bookmark navigator view.
073:             */
074:            public void run() {
075:                // Get the markers from the clipboard
076:                MarkerTransfer transfer = MarkerTransfer.getInstance();
077:                IMarker[] markerData = (IMarker[]) clipboard
078:                        .getContents(transfer);
079:                paste(markerData);
080:            }
081:
082:            void paste(final IMarker[] markers) {
083:                if (markers == null) {
084:                    return;
085:                }
086:
087:                final ArrayList newMarkerTypes = new ArrayList();
088:                final ArrayList newMarkerAttributes = new ArrayList();
089:                final ArrayList newMarkerResources = new ArrayList();
090:
091:                try {
092:                    ResourcesPlugin.getWorkspace().run(
093:                            new IWorkspaceRunnable() {
094:                                public void run(IProgressMonitor monitor)
095:                                        throws CoreException {
096:                                    for (int i = 0; i < markers.length; i++) {
097:                                        // Collect info about the markers to be pasted.
098:                                        newMarkerTypes
099:                                                .add(markers[i].getType());
100:                                        newMarkerResources.add(markers[i]
101:                                                .getResource());
102:                                        newMarkerAttributes.add(markers[i]
103:                                                .getAttributes());
104:
105:                                    }
106:                                }
107:                            }, null);
108:                } catch (CoreException e) {
109:                    ErrorDialog.openError(part.getSite().getShell(),
110:                            MarkerMessages.PasteMarker_errorTitle, null, e
111:                                    .getStatus());
112:                    return;
113:                }
114:
115:                final String[] types = (String[]) newMarkerTypes
116:                        .toArray(new String[newMarkerTypes.size()]);
117:                final Map[] attrs = (Map[]) newMarkerAttributes
118:                        .toArray(new Map[newMarkerAttributes.size()]);
119:                final IResource[] resources = (IResource[]) newMarkerResources
120:                        .toArray(new IResource[newMarkerResources.size()]);
121:                String operationTitle = NLS.bind(
122:                        MarkerMessages.qualifiedMarkerCommand_title,
123:                        MarkerMessages.pasteAction_title, markerName);
124:                final CreateMarkersOperation op = new CreateMarkersOperation(
125:                        types, attrs, resources, operationTitle);
126:                execute(op, MarkerMessages.PasteMarker_errorTitle, null,
127:                        WorkspaceUndoUtil.getUIInfoAdapter(part.getSite()
128:                                .getShell()));
129:
130:                // Need to do this in an asyncExec, even though we're in the UI thread
131:                // here,
132:                // since the marker view updates itself with the addition in an
133:                // asyncExec,
134:                // which hasn't been processed yet.
135:                // Must be done outside the create marker operation above since
136:                // notification for add is
137:                // sent after the operation is executed.
138:                if (getSelectionProvider() != null && op.getMarkers() != null) {
139:                    part.getSite().getShell().getDisplay().asyncExec(
140:                            new Runnable() {
141:                                public void run() {
142:                                    getSelectionProvider().setSelection(
143:                                            new StructuredSelection(op
144:                                                    .getMarkers()));
145:                                }
146:                            });
147:                }
148:            }
149:
150:            void updateEnablement() {
151:                setEnabled(false);
152:                if (clipboard == null) {
153:                    return;
154:                }
155:
156:                // Paste if clipboard contains pastable markers
157:                MarkerTransfer transfer = MarkerTransfer.getInstance();
158:                IMarker[] markerData = (IMarker[]) clipboard
159:                        .getContents(transfer);
160:                if (markerData == null || markerData.length < 1
161:                        || pastableTypes == null) {
162:                    return;
163:                }
164:                for (int i = 0; i < markerData.length; i++) {
165:                    try {
166:                        IMarker marker = markerData[i];
167:                        if (!marker.exists()) {
168:                            break;
169:                        }
170:                        boolean pastable = false;
171:                        for (int j = 0; j < pastableTypes.length; j++) {
172:                            if (marker.isSubtypeOf(pastableTypes[j])) {
173:                                pastable = true;
174:                                break;
175:                            }
176:                        }
177:                        if (!pastable) {
178:                            return;
179:                        }
180:                        if (!Util.isEditable(marker)) {
181:                            return;
182:                        }
183:                    } catch (CoreException e) {
184:                        return;
185:                    }
186:                }
187:                setEnabled(true);
188:            }
189:
190:            /**
191:             * @param strings
192:             */
193:            void setPastableTypes(String[] strings) {
194:                pastableTypes = strings;
195:            }
196:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.