Source Code Cross Referenced for CreatePageAction.java in  » GIS » udig-1.1 » net » refractions » udig » printing » 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 » GIS » udig 1.1 » net.refractions.udig.printing.ui.actions 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004,
003:         * Refractions Research Inc. This library is free software; you can redistribute it and/or modify it
004:         * under the terms of the GNU Lesser General Public License as published by the Free Software
005:         * Foundation; version 2.1 of the License. This library is distributed in the hope that it will be
006:         * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
007:         * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
008:         */
009:        package net.refractions.udig.printing.ui.actions;
010:
011:        import java.awt.print.PageFormat;
012:        import java.awt.print.PrinterJob;
013:        import java.text.MessageFormat;
014:        import java.util.Iterator;
015:        import java.util.Locale;
016:
017:        import net.refractions.udig.printing.model.Box;
018:        import net.refractions.udig.printing.model.ModelFactory;
019:        import net.refractions.udig.printing.model.Page;
020:        import net.refractions.udig.printing.ui.Template;
021:        import net.refractions.udig.printing.ui.TemplateFactory;
022:        import net.refractions.udig.printing.ui.internal.BasicTemplateFactory;
023:        import net.refractions.udig.printing.ui.internal.Messages;
024:        import net.refractions.udig.printing.ui.internal.PrintingPlugin;
025:        import net.refractions.udig.project.internal.Map;
026:        import net.refractions.udig.project.internal.Project;
027:        import net.refractions.udig.project.ui.internal.MapEditorInput;
028:        import net.refractions.udig.project.ui.internal.ProjectExplorer;
029:
030:        import org.eclipse.draw2d.geometry.Dimension;
031:        import org.eclipse.emf.ecore.util.EcoreUtil;
032:        import org.eclipse.jface.action.IAction;
033:        import org.eclipse.jface.dialogs.MessageDialog;
034:        import org.eclipse.jface.viewers.ArrayContentProvider;
035:        import org.eclipse.jface.viewers.ILabelProvider;
036:        import org.eclipse.jface.viewers.ISelection;
037:        import org.eclipse.jface.viewers.LabelProvider;
038:        import org.eclipse.jface.viewers.StructuredSelection;
039:        import org.eclipse.jface.window.Window;
040:        import org.eclipse.swt.widgets.Display;
041:        import org.eclipse.ui.IEditorActionDelegate;
042:        import org.eclipse.ui.IEditorInput;
043:        import org.eclipse.ui.IEditorPart;
044:        import org.eclipse.ui.PlatformUI;
045:        import org.eclipse.ui.dialogs.ListDialog;
046:
047:        /**
048:         * Creates a Page using the current map
049:         * 
050:         * @author Richard Gould
051:         */
052:        public class CreatePageAction implements  IEditorActionDelegate {
053:
054:            public void run(IAction action) {
055:                IEditorInput input = PlatformUI.getWorkbench()
056:                        .getActiveWorkbenchWindow().getActivePage()
057:                        .getActiveEditor().getEditorInput();
058:
059:                if (!(input instanceof  MapEditorInput)) {
060:                    MessageDialog.openError(Display.getDefault()
061:                            .getActiveShell(),
062:                            Messages.CreatePageAction_printError_title,
063:                            Messages.CreatePageAction_printError_text);
064:                }
065:
066:                final java.util.Map<String, TemplateFactory> templateFactories = PrintingPlugin
067:                        .getDefault().getTemplateFactories();
068:
069:                //TODO move to a preference initializer
070:                PrintingPlugin
071:                        .getDefault()
072:                        .getPluginPreferences()
073:                        .setValue(PrintingPlugin.PREF_DEFAULT_TEMPLATE,
074:                                "net.refractions.udig.printing.ui.internal.BasicTemplate"); //$NON-NLS-1$
075:
076:                String defaultTemplate = PrintingPlugin.getDefault()
077:                        .getPluginPreferences().getString(
078:                                PrintingPlugin.PREF_DEFAULT_TEMPLATE);
079:
080:                TemplateFactory templateFactory;
081:
082:                ListDialog dialog = new ListDialog(Display.getDefault()
083:                        .getActiveShell());
084:                dialog.setTitle(Messages.CreatePageAction_dialog_title);
085:                dialog.setMessage(Messages.CreatePageAction_dialog_message);
086:                dialog.setInput(templateFactories.values());
087:                ArrayContentProvider provider = new ArrayContentProvider();
088:                dialog.setContentProvider(provider);
089:
090:                ILabelProvider labelProvider = new LabelProvider() {
091:                    public String getText(Object element) {
092:                        return ((TemplateFactory) element).getName();
093:                    }
094:                };
095:                dialog.setLabelProvider(labelProvider);
096:
097:                templateFactory = (TemplateFactory) PrintingPlugin.getDefault()
098:                        .getTemplateFactories().get(defaultTemplate);
099:
100:                dialog.setInitialSelections(new Object[] { templateFactory });
101:                int result = dialog.open();
102:                if (result == Window.CANCEL || dialog.getResult().length == 0) {
103:                    return;
104:                }
105:
106:                Template template = null;
107:
108:                templateFactory = ((TemplateFactory) dialog.getResult()[0]);
109:
110:                if (templateFactory == null) {
111:                    PrintingPlugin
112:                            .log(
113:                                    Messages.CreatePageAction_error_cannotFindDefaultTemplate,
114:                                    null);
115:
116:                    TemplateFactory firstAvailable = (TemplateFactory) templateFactories
117:                            .values().iterator().next();
118:                    if (firstAvailable == null) {
119:                        PrintingPlugin
120:                                .log(
121:                                        "Unable to locate any templates, resorting to hard coded default.",
122:                                        null);
123:                        template = new BasicTemplateFactory().createTemplate();
124:                    } else {
125:                        template = firstAvailable.createTemplate();
126:                    }
127:                } else {
128:                    template = templateFactory.createTemplate();
129:                }
130:
131:                Map map = null;
132:                Project project = null;
133:
134:                Map oldMap = (Map) ((MapEditorInput) input).getProjectElement();
135:                project = oldMap.getProjectInternal();
136:
137:                map = (Map) EcoreUtil.copy(oldMap);
138:
139:                project.getElementsInternal().add(map);
140:
141:                MessageFormat formatter = new MessageFormat(
142:                        Messages.CreatePageAction_newPageName, Locale
143:                                .getDefault());
144:                map.setName(formatter.format(new Object[] { map.getName() }));
145:
146:                PageFormat pageFormat = PrinterJob.getPrinterJob()
147:                        .defaultPage();
148:                int width = new Double(pageFormat.getImageableWidth())
149:                        .intValue();
150:                int height = new Double(pageFormat.getImageableHeight())
151:                        .intValue();
152:
153:                Page page = ModelFactory.eINSTANCE.createPage();
154:
155:                page.setSize(new Dimension(width, height));
156:                if (page.getName() == null || page.getName().length() == 0) {
157:                    page.setName("Untitled");
158:                }
159:
160:                page.setProjectInternal(project);
161:
162:                template.init(page, map, width, height);
163:                Iterator<Box> iter = template.iterator();
164:                while (iter.hasNext()) {
165:                    page.getBoxes().add(iter.next());
166:                }
167:
168:                ProjectExplorer.getProjectExplorer().open(page);
169:                ProjectExplorer.getProjectExplorer().selectReveal(
170:                        new StructuredSelection(page));
171:
172:            }
173:
174:            /**
175:             * TODO summary sentence for setActiveEditor ...
176:             * 
177:             * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction,
178:             *      org.eclipse.ui.IEditorPart)
179:             * @param action
180:             * @param targetEditor
181:             */
182:            public void setActiveEditor(IAction action, IEditorPart targetEditor) {
183:            }
184:
185:            /**
186:             * TODO summary sentence for selectionChanged ...
187:             * 
188:             * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
189:             *      org.eclipse.jface.viewers.ISelection)
190:             * @param action
191:             * @param selection
192:             */
193:            public void selectionChanged(IAction action, ISelection selection) {
194:            }
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.