Source Code Cross Referenced for ExternalizeStringsWizardPage.java in  » IDE-Eclipse » Eclipse-plug-in-development » org » eclipse » pde » internal » ui » nls » 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 » Eclipse plug in development » org.eclipse.pde.internal.ui.nls 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2005, 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.pde.internal.ui.nls;
011:
012:        import java.util.Properties;
013:
014:        import org.eclipse.core.filebuffers.FileBuffers;
015:        import org.eclipse.core.filebuffers.ITextFileBufferManager;
016:        import org.eclipse.core.filebuffers.LocationKind;
017:        import org.eclipse.core.resources.IFile;
018:        import org.eclipse.core.runtime.CoreException;
019:        import org.eclipse.core.runtime.NullProgressMonitor;
020:        import org.eclipse.jface.dialogs.Dialog;
021:        import org.eclipse.jface.resource.JFaceResources;
022:        import org.eclipse.jface.text.Document;
023:        import org.eclipse.jface.text.IDocument;
024:        import org.eclipse.jface.text.source.SourceViewer;
025:        import org.eclipse.jface.viewers.CellEditor;
026:        import org.eclipse.jface.viewers.CheckStateChangedEvent;
027:        import org.eclipse.jface.viewers.CheckboxTableViewer;
028:        import org.eclipse.jface.viewers.ICellModifier;
029:        import org.eclipse.jface.viewers.ICheckStateListener;
030:        import org.eclipse.jface.viewers.IContentProvider;
031:        import org.eclipse.jface.viewers.ISelectionChangedListener;
032:        import org.eclipse.jface.viewers.IStructuredContentProvider;
033:        import org.eclipse.jface.viewers.IStructuredSelection;
034:        import org.eclipse.jface.viewers.ITreeContentProvider;
035:        import org.eclipse.jface.viewers.SelectionChangedEvent;
036:        import org.eclipse.jface.viewers.StructuredSelection;
037:        import org.eclipse.jface.viewers.TextCellEditor;
038:        import org.eclipse.jface.viewers.Viewer;
039:        import org.eclipse.jface.viewers.ViewerFilter;
040:        import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
041:        import org.eclipse.pde.core.plugin.IPluginModelBase;
042:        import org.eclipse.pde.internal.ui.IHelpContextIds;
043:        import org.eclipse.pde.internal.ui.PDEPlugin;
044:        import org.eclipse.pde.internal.ui.PDEUIMessages;
045:        import org.eclipse.pde.internal.ui.editor.context.ManifestDocumentSetupParticipant;
046:        import org.eclipse.pde.internal.ui.editor.context.XMLDocumentSetupParticpant;
047:        import org.eclipse.pde.internal.ui.editor.text.ColorManager;
048:        import org.eclipse.pde.internal.ui.editor.text.IColorManager;
049:        import org.eclipse.pde.internal.ui.editor.text.ManifestConfiguration;
050:        import org.eclipse.pde.internal.ui.editor.text.XMLConfiguration;
051:        import org.eclipse.pde.internal.ui.refactoring.PDERefactor;
052:        import org.eclipse.pde.internal.ui.wizards.ListUtil;
053:        import org.eclipse.swt.SWT;
054:        import org.eclipse.swt.custom.SashForm;
055:        import org.eclipse.swt.events.ModifyEvent;
056:        import org.eclipse.swt.events.ModifyListener;
057:        import org.eclipse.swt.events.SelectionAdapter;
058:        import org.eclipse.swt.events.SelectionEvent;
059:        import org.eclipse.swt.layout.GridData;
060:        import org.eclipse.swt.layout.GridLayout;
061:        import org.eclipse.swt.widgets.Button;
062:        import org.eclipse.swt.widgets.Composite;
063:        import org.eclipse.swt.widgets.Control;
064:        import org.eclipse.swt.widgets.Label;
065:        import org.eclipse.swt.widgets.Table;
066:        import org.eclipse.swt.widgets.TableColumn;
067:        import org.eclipse.swt.widgets.TableItem;
068:        import org.eclipse.swt.widgets.Text;
069:        import org.eclipse.swt.widgets.TreeItem;
070:        import org.eclipse.text.edits.MalformedTreeException;
071:        import org.eclipse.ui.PlatformUI;
072:        import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer;
073:
074:        public class ExternalizeStringsWizardPage extends UserInputWizardPage {
075:
076:            public static final String PAGE_NAME = "ExternalizeStringsWizardPage"; //$NON-NLS-1$
077:
078:            public static final int EXTERN = 0;
079:            public static final int VALUE = 1;
080:            public static final int KEY = 2;
081:            private static final int SIZE = 3; // column counter
082:            private static final String[] TABLE_PROPERTIES = new String[SIZE];
083:            private static final String[] TABLE_COLUMNS = new String[SIZE];
084:
085:            static {
086:                TABLE_PROPERTIES[EXTERN] = "extern"; //$NON-NLS-1$
087:                TABLE_PROPERTIES[VALUE] = "value"; //$NON-NLS-1$
088:                TABLE_PROPERTIES[KEY] = "key"; //$NON-NLS-1$
089:                TABLE_COLUMNS[EXTERN] = ""; //$NON-NLS-1$
090:                TABLE_COLUMNS[VALUE] = PDEUIMessages.ExternalizeStringsWizardPage_value;
091:                TABLE_COLUMNS[KEY] = PDEUIMessages.ExternalizeStringsWizardPage_subKey;
092:            }
093:
094:            private class ModelChangeContentProvider implements 
095:                    ITreeContentProvider, IContentProvider {
096:
097:                public Object[] getElements(Object parent) {
098:                    return fModelChangeTable.getAllModelChanges().toArray();
099:                }
100:
101:                public Object[] getChildren(Object parentElement) {
102:                    if (!(parentElement instanceof  ModelChange))
103:                        return new Object[0];
104:                    return ((ModelChange) parentElement).getModelChangeFiles();
105:                }
106:
107:                public Object getParent(Object element) {
108:                    if (element instanceof  ModelChangeFile) {
109:                        return ((ModelChangeFile) element).getModel();
110:                    }
111:                    return null;
112:                }
113:
114:                public boolean hasChildren(Object element) {
115:                    return element instanceof  ModelChange;
116:                }
117:
118:                public void dispose() {
119:                }
120:
121:                public void inputChanged(Viewer viewer, Object oldInput,
122:                        Object newInput) {
123:                }
124:            }
125:
126:            private class ExternalizeStringsCellModifier implements 
127:                    ICellModifier {
128:
129:                public boolean canModify(Object element, String property) {
130:                    return (property != null
131:                            && (element instanceof  ModelChangeElement)
132:                            && !TABLE_PROPERTIES[VALUE].equals(property)
133:                            && (isPageComplete() || element
134:                                    .equals(fErrorElement)) && (TABLE_PROPERTIES[KEY]
135:                            .equals(property) && ((ModelChangeElement) element)
136:                            .isExternalized()));
137:
138:                }
139:
140:                public Object getValue(Object element, String property) {
141:                    if (element instanceof  ModelChangeElement) {
142:                        ModelChangeElement changeElement = (ModelChangeElement) element;
143:                        if (TABLE_PROPERTIES[KEY].equals(property)) {
144:                            return StringHelper.unwindEscapeChars(changeElement
145:                                    .getKey());
146:                        }
147:                    }
148:                    return ""; //$NON-NLS-1$
149:                }
150:
151:                public void modify(Object element, String property, Object value) {
152:                    if (element instanceof  TableItem) {
153:                        Object data = ((TableItem) element).getData();
154:                        if (data instanceof  ModelChangeElement) {
155:                            ModelChangeElement changeElement = (ModelChangeElement) data;
156:                            if (TABLE_PROPERTIES[KEY].equals(property)) {
157:                                String newKey = StringHelper
158:                                        .windEscapeChars((String) value);
159:                                validateKey(newKey, changeElement);
160:                                changeElement.setKey(newKey);
161:                                fPropertiesViewer.update(data, null);
162:                            }
163:                        }
164:                    }
165:                }
166:            }
167:
168:            private ModelChangeTable fModelChangeTable;
169:
170:            private ContainerCheckedTreeViewer fInputViewer;
171:            private Button fSelectAll;
172:            private Button fDeselectAll;
173:            private Label fProjectLabel;
174:            private Text fLocalizationText;
175:            private CheckboxTableViewer fPropertiesViewer;
176:            private Table fTable;
177:            private SourceViewer fSourceViewer;
178:
179:            private ViewerFilter fErrorElementFilter;
180:            private ModifyListener fModifyListener;
181:
182:            private Object fCurrSelection;
183:            private ModelChangeElement fErrorElement;
184:            private String fPreErrorKey;
185:
186:            private IDocument fEmptyDoc;
187:            private IColorManager fColorManager;
188:            private XMLConfiguration fXMLConfig;
189:            private XMLDocumentSetupParticpant fXMLSetupParticipant;
190:            private ManifestDocumentSetupParticipant fManifestSetupParticipant;
191:
192:            private ManifestConfiguration fManifestConfig;
193:
194:            protected ExternalizeStringsWizardPage(ModelChangeTable changeTable) {
195:                super (PAGE_NAME);
196:                setTitle(PDEUIMessages.ExternalizeStringsWizardPage_pageTitle);
197:                setDescription(PDEUIMessages.ExternalizeStringsWizardPage_pageDescription);
198:                fModelChangeTable = changeTable;
199:                fErrorElementFilter = new ViewerFilter() {
200:                    public boolean select(Viewer viewer, Object parentElement,
201:                            Object element) {
202:                        if (!(element instanceof  ModelChangeElement))
203:                            return false;
204:                        ModelChangeElement change = (ModelChangeElement) element;
205:                        return change.equals(fErrorElement);
206:                    }
207:                };
208:                fModifyListener = new ModifyListener() {
209:                    public void modifyText(ModifyEvent e) {
210:                        String localization = fLocalizationText.getText();
211:                        if (StringHelper.isValidLocalization(localization)) {
212:                            setEnabled(fLocalizationText, true);
213:                            setPageComplete(hasCheckedElements());
214:                            setErrorMessage(null);
215:                            if (fCurrSelection instanceof  ModelChange) {
216:                                ((ModelChange) fCurrSelection)
217:                                        .setBundleLocalization(fLocalizationText
218:                                                .getText());
219:                            } else if (fCurrSelection instanceof  ModelChangeFile) {
220:                                ((ModelChangeFile) fCurrSelection).getModel()
221:                                        .setBundleLocalization(
222:                                                fLocalizationText.getText());
223:                            }
224:                        } else {
225:                            setEnabled(fLocalizationText, false);
226:                            fLocalizationText.setEditable(true);
227:                            setPageComplete(false);
228:                            setErrorMessage(PDEUIMessages.ExternalizeStringsWizardPage_badLocalizationError);
229:                        }
230:                    }
231:                };
232:                fColorManager = ColorManager.getDefault();
233:                fXMLConfig = new XMLConfiguration(fColorManager);
234:                fXMLSetupParticipant = new XMLDocumentSetupParticpant();
235:                fManifestConfig = new ManifestConfiguration(fColorManager);
236:                fManifestSetupParticipant = new ManifestDocumentSetupParticipant();
237:            }
238:
239:            public void dispose() {
240:                fColorManager.dispose();
241:                super .dispose();
242:            }
243:
244:            public void createControl(Composite parent) {
245:
246:                SashForm super Sash = new SashForm(parent, SWT.HORIZONTAL);
247:                super Sash.setFont(parent.getFont());
248:                super Sash.setLayoutData(new GridData(GridData.FILL_BOTH));
249:
250:                createInputContents(super Sash);
251:
252:                SashForm sash = new SashForm(super Sash, SWT.VERTICAL);
253:                sash.setFont(super Sash.getFont());
254:                sash.setLayoutData(new GridData(GridData.FILL_BOTH));
255:
256:                createTableViewer(sash);
257:                createSourceViewer(sash);
258:                initialize();
259:
260:                setPageComplete(hasCheckedElements());
261:
262:                super Sash.setWeights(new int[] { 4, 7 });
263:                setControl(super Sash);
264:                Dialog.applyDialogFont(super Sash);
265:
266:                PlatformUI.getWorkbench().getHelpSystem().setHelp(super Sash,
267:                        IHelpContextIds.EXTERNALIZE_STRINGS_PAGE);
268:            }
269:
270:            private void createInputContents(Composite composite) {
271:                Composite fileComposite = new Composite(composite, SWT.NONE);
272:                fileComposite.setLayout(new GridLayout());
273:                fileComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
274:
275:                Label label = new Label(fileComposite, SWT.NONE);
276:                label
277:                        .setText(PDEUIMessages.ExternalizeStringsWizardPage_resourcelabel);
278:                fInputViewer = new ContainerCheckedTreeViewer(fileComposite,
279:                        SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE | SWT.BORDER);
280:                fInputViewer
281:                        .setContentProvider(new ModelChangeContentProvider());
282:                fInputViewer.setLabelProvider(new ModelChangeLabelProvider());
283:                GridData gd = new GridData(GridData.FILL_BOTH);
284:                gd.heightHint = 250;
285:                fInputViewer.getTree().setLayoutData(gd);
286:                fInputViewer
287:                        .addSelectionChangedListener(new ISelectionChangedListener() {
288:                            public void selectionChanged(
289:                                    SelectionChangedEvent event) {
290:                                handleSelectionChanged(event);
291:                            }
292:                        });
293:                fInputViewer.addCheckStateListener(new ICheckStateListener() {
294:                    public void checkStateChanged(CheckStateChangedEvent event) {
295:                        setPageComplete(hasCheckedElements());
296:                    }
297:                });
298:                fInputViewer.setComparator(ListUtil.PLUGIN_COMPARATOR);
299:
300:                Composite buttonComposite = new Composite(fileComposite,
301:                        SWT.NONE);
302:                GridLayout layout = new GridLayout(2, true);
303:                layout.marginHeight = layout.marginWidth = 0;
304:                buttonComposite.setLayout(layout);
305:                buttonComposite.setLayoutData(new GridData(
306:                        GridData.FILL_HORIZONTAL));
307:
308:                fSelectAll = new Button(buttonComposite, SWT.PUSH);
309:                fSelectAll
310:                        .setText(PDEUIMessages.ExternalizeStringsWizardPage_selectAllButton);
311:                fSelectAll
312:                        .setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
313:                fSelectAll.addSelectionListener(new SelectionAdapter() {
314:                    public void widgetSelected(SelectionEvent e) {
315:                        fInputViewer.setCheckedElements(fModelChangeTable
316:                                .getAllModelChanges().toArray());
317:                        setPageComplete(hasCheckedElements());
318:                    }
319:                });
320:                fDeselectAll = new Button(buttonComposite, SWT.PUSH);
321:                fDeselectAll
322:                        .setText(PDEUIMessages.ExternalizeStringsWizardPage_deselectAllButton);
323:                fDeselectAll.setLayoutData(new GridData(
324:                        GridData.FILL_HORIZONTAL));
325:                fDeselectAll.addSelectionListener(new SelectionAdapter() {
326:                    public void widgetSelected(SelectionEvent e) {
327:                        fInputViewer.setCheckedElements(new Object[0]);
328:                        setPageComplete(hasCheckedElements());
329:                    }
330:                });
331:
332:                Composite infoComposite = new Composite(fileComposite, SWT.NONE);
333:                layout = new GridLayout();
334:                layout.marginHeight = 0;
335:                infoComposite.setLayout(layout);
336:                infoComposite.setLayoutData(new GridData(
337:                        GridData.FILL_HORIZONTAL));
338:
339:                Label project = new Label(infoComposite, SWT.NONE);
340:                project
341:                        .setText(PDEUIMessages.ExternalizeStringsWizardPage_projectLabel);
342:                fProjectLabel = new Label(infoComposite, SWT.NONE);
343:                gd = new GridData(GridData.FILL_HORIZONTAL);
344:                gd.horizontalIndent = 10;
345:                fProjectLabel.setLayoutData(gd);
346:                fProjectLabel
347:                        .setText(PDEUIMessages.ExternalizeStringsWizardPage_noUnderlyingResource);
348:
349:                Label properties = new Label(infoComposite, SWT.NONE);
350:                properties
351:                        .setText(PDEUIMessages.ExternalizeStringsWizardPage_localizationLabel);
352:                fLocalizationText = new Text(infoComposite, SWT.BORDER);
353:                gd = new GridData(GridData.FILL_HORIZONTAL);
354:                gd.horizontalIndent = 10;
355:                fLocalizationText.setLayoutData(gd);
356:                fLocalizationText
357:                        .setText(PDEUIMessages.ExternalizeStringsWizardPage_noUnderlyingResource);
358:                fLocalizationText.addModifyListener(fModifyListener);
359:
360:                fInputViewer.setInput(PDEPlugin.getDefault());
361:            }
362:
363:            private void createTableViewer(Composite parent) {
364:                Composite composite = new Composite(parent, SWT.NONE);
365:                composite.setFont(parent.getFont());
366:                composite.setLayoutData(new GridData(GridData.FILL_BOTH));
367:                composite.setLayout(new GridLayout());
368:
369:                Label label = new Label(composite, SWT.NONE);
370:                label
371:                        .setText(PDEUIMessages.ExternalizeStringsWizardPage_propertiesLabel);
372:                label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
373:
374:                fPropertiesViewer = CheckboxTableViewer.newCheckList(composite,
375:                        SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION
376:                                | SWT.HIDE_SELECTION | SWT.BORDER);
377:                fTable = fPropertiesViewer.getTable();
378:                fTable.setFont(composite.getFont());
379:                fTable.setLayoutData(new GridData(GridData.FILL_BOTH));
380:                fTable.setLayout(new GridLayout());
381:                fTable.setLinesVisible(true);
382:                fTable.setHeaderVisible(true);
383:
384:                for (int i = 0; i < TABLE_COLUMNS.length; i++) {
385:                    TableColumn tc = new TableColumn(fTable, SWT.NONE);
386:                    tc.setText(TABLE_COLUMNS[i]);
387:                    tc.setResizable(i != 0);
388:                    tc.setWidth(i == 0 ? 20 : 200);
389:                }
390:
391:                fPropertiesViewer.setUseHashlookup(true);
392:                fPropertiesViewer.setCellEditors(createCellEditors());
393:                fPropertiesViewer.setColumnProperties(TABLE_PROPERTIES);
394:                fPropertiesViewer
395:                        .setCellModifier(new ExternalizeStringsCellModifier());
396:                fPropertiesViewer
397:                        .setContentProvider(new IStructuredContentProvider() {
398:                            public Object[] getElements(Object inputElement) {
399:                                if (fInputViewer.getSelection() instanceof  IStructuredSelection) {
400:                                    Object selection = ((IStructuredSelection) fInputViewer
401:                                            .getSelection()).getFirstElement();
402:                                    if (selection instanceof  ModelChangeFile) {
403:                                        ModelChangeFile cf = (ModelChangeFile) selection;
404:                                        return (cf).getModel()
405:                                                .getChangesInFile(cf.getFile())
406:                                                .toArray();
407:                                    }
408:                                }
409:                                return new Object[0];
410:                            }
411:
412:                            public void dispose() {
413:                            }
414:
415:                            public void inputChanged(Viewer viewer,
416:                                    Object oldInput, Object newInput) {
417:                            }
418:                        });
419:                fPropertiesViewer
420:                        .setLabelProvider(new ExternalizeStringsLabelProvider());
421:                fPropertiesViewer
422:                        .addSelectionChangedListener(new ISelectionChangedListener() {
423:                            public void selectionChanged(
424:                                    SelectionChangedEvent event) {
425:                                handlePropertySelection();
426:                            }
427:                        });
428:                fPropertiesViewer
429:                        .addCheckStateListener(new ICheckStateListener() {
430:                            public void checkStateChanged(
431:                                    CheckStateChangedEvent event) {
432:                                Object element = event.getElement();
433:                                if (element instanceof  ModelChangeElement) {
434:                                    ((ModelChangeElement) element)
435:                                            .setExternalized(event.getChecked());
436:                                    fPropertiesViewer.update(element, null);
437:                                }
438:                            }
439:                        });
440:                fPropertiesViewer.setInput(new Object());
441:            }
442:
443:            private void createSourceViewer(Composite parent) {
444:                Composite composite = new Composite(parent, SWT.NONE);
445:                composite.setLayoutData(new GridData(GridData.FILL_BOTH));
446:                composite.setLayout(new GridLayout());
447:
448:                Label label = new Label(composite, SWT.NONE);
449:                label
450:                        .setText(PDEUIMessages.ExternalizeStringsWizardPage_sourceLabel);
451:                label.setLayoutData(new GridData());
452:
453:                fSourceViewer = new SourceViewer(composite, null, SWT.V_SCROLL
454:                        | SWT.H_SCROLL | SWT.BORDER);
455:                fSourceViewer.setEditable(false);
456:                fSourceViewer.getTextWidget().setFont(
457:                        JFaceResources.getTextFont());
458:                fSourceViewer.getControl().setLayoutData(
459:                        new GridData(GridData.FILL_BOTH));
460:
461:                fEmptyDoc = new Document();
462:                fSourceViewer.setDocument(fEmptyDoc);
463:            }
464:
465:            // must set selection after source viewer is created, otherwise you get an NPE.
466:            private void initialize() {
467:                Object[] preSelect = fModelChangeTable.getPreSelected();
468:                fInputViewer.setSelection(new StructuredSelection(preSelect));
469:                fInputViewer.setCheckedElements(fModelChangeTable
470:                        .getPreSelected());
471:            }
472:
473:            private void handleSelectionChanged(SelectionChangedEvent event) {
474:                if (!(event.getSelection() instanceof  IStructuredSelection))
475:                    return;
476:                Object selection = (((IStructuredSelection) event
477:                        .getSelection()).getFirstElement());
478:                if (selection == null) {
479:                    fCurrSelection = null;
480:                    fSourceViewer.setDocument(fEmptyDoc);
481:                } else if (selection.equals(fCurrSelection)) {
482:                    return;
483:                } else if (selection instanceof  ModelChangeFile) {
484:                    fCurrSelection = selection;
485:                    IFile file = ((ModelChangeFile) fCurrSelection).getFile();
486:                    NullProgressMonitor monitor = new NullProgressMonitor();
487:                    ITextFileBufferManager manager = FileBuffers
488:                            .getTextFileBufferManager();
489:                    try {
490:                        try {
491:                            manager.connect(file.getFullPath(),
492:                                    LocationKind.IFILE, monitor);
493:                            updateSourceViewer(manager, file);
494:                        } catch (MalformedTreeException e) {
495:                        } finally {
496:                            manager.disconnect(file.getFullPath(),
497:                                    LocationKind.IFILE, monitor);
498:                        }
499:                    } catch (CoreException e) {
500:                    }
501:                } else if (selection instanceof  ModelChange) {
502:                    fCurrSelection = selection;
503:                    fSourceViewer.setDocument(fEmptyDoc);
504:                    updatePropertiesLabel(((ModelChange) fCurrSelection)
505:                            .getParentModel());
506:                }
507:                refreshPropertiesViewer(false);
508:            }
509:
510:            private void refreshPropertiesViewer(boolean updateLabels) {
511:                fPropertiesViewer.refresh(updateLabels);
512:                TableItem[] items = fTable.getItems();
513:                for (int i = 0; i < items.length; i++) {
514:                    if (!(items[i].getData() instanceof  ModelChangeElement))
515:                        continue;
516:                    ModelChangeElement element = (ModelChangeElement) items[i]
517:                            .getData();
518:                    fPropertiesViewer.setChecked(element, element
519:                            .isExternalized());
520:                }
521:            }
522:
523:            private void updateSourceViewer(ITextFileBufferManager manager,
524:                    IFile sourceFile) {
525:                IDocument document = manager.getTextFileBuffer(
526:                        sourceFile.getFullPath(), LocationKind.IFILE)
527:                        .getDocument();
528:                TreeItem item = fInputViewer.getTree().getSelection()[0];
529:                IPluginModelBase model = ((ModelChange) item.getParentItem()
530:                        .getData()).getParentModel();
531:
532:                if (fSourceViewer.getDocument() != null)
533:                    fSourceViewer.unconfigure();
534:                if (sourceFile.getFileExtension().equalsIgnoreCase("xml")) { //$NON-NLS-1$
535:                    fSourceViewer.configure(fXMLConfig);
536:                    fXMLSetupParticipant.setup(document);
537:                } else {
538:                    fSourceViewer.configure(fManifestConfig);
539:                    fManifestSetupParticipant.setup(document);
540:                }
541:
542:                fSourceViewer.setDocument(document);
543:                updatePropertiesLabel(model);
544:            }
545:
546:            private void updatePropertiesLabel(IPluginModelBase model) {
547:                ModelChange modelChange = fModelChangeTable
548:                        .getModelChange(model);
549:                fProjectLabel.setText(model.getUnderlyingResource()
550:                        .getProject().getName());
551:                fLocalizationText.setEditable(!modelChange.localizationSet());
552:                fLocalizationText.setText(modelChange.getBundleLocalization());
553:            }
554:
555:            private void handlePropertySelection() {
556:                if (!(fPropertiesViewer.getSelection() instanceof  IStructuredSelection))
557:                    return;
558:                Object selection = (((IStructuredSelection) fPropertiesViewer
559:                        .getSelection()).getFirstElement());
560:                if (selection instanceof  ModelChangeElement
561:                        && fSourceViewer.getDocument() != null) {
562:                    ModelChangeElement element = (ModelChangeElement) selection;
563:                    int offset = element.getOffset();
564:                    int length = element.getLength();
565:                    fSourceViewer.setSelectedRange(offset, length);
566:                    fSourceViewer.revealRange(offset, length);
567:                }
568:            }
569:
570:            private CellEditor[] createCellEditors() {
571:                final CellEditor editors[] = new CellEditor[SIZE];
572:                editors[EXTERN] = null;
573:                editors[VALUE] = null;
574:                editors[KEY] = new TextCellEditor(fTable);
575:                return editors;
576:            }
577:
578:            private void validateKey(String key, ModelChangeElement element) {
579:                ModelChange modelChange = ((ModelChangeFile) fCurrSelection)
580:                        .getModel();
581:                Properties properties = modelChange.getProperties();
582:                String error = null;
583:                String oldKey = (fPreErrorKey != null) ? fPreErrorKey : element
584:                        .getKey();
585:                if (key.equals(fPreErrorKey)) {
586:                    error = null;
587:                } else if (key.trim().length() < 1) {
588:                    error = getErrorMessage(
589:                            PDEUIMessages.ExternalizeStringsWizardPage_keyEmptyError,
590:                            oldKey);
591:                } else if (key.charAt(0) == '#' || key.charAt(0) == '!'
592:                        || key.charAt(0) == '%') {
593:                    error = getErrorMessage(
594:                            PDEUIMessages.ExternalizeStringsWizardPage_keyCommentError,
595:                            oldKey);
596:                } else if (key.indexOf(':') != -1 || key.indexOf('=') != -1
597:                        || key.indexOf(' ') != -1) {
598:                    error = getErrorMessage(
599:                            PDEUIMessages.ExternalizeStringsWizardPage_keyError,
600:                            oldKey);
601:                } else if ((!key.equals(oldKey) || fPreErrorKey != null)
602:                        && properties.containsKey(key)) {
603:                    error = getErrorMessage(
604:                            PDEUIMessages.ExternalizeStringsWizardPage_keyDuplicateError,
605:                            oldKey);
606:                }
607:
608:                setErrorMessage(error);
609:                setPageComplete(error == null && hasCheckedElements());
610:                if (error == null) {
611:                    fErrorElement = null;
612:                    fPreErrorKey = null;
613:                    setEnabled(fPropertiesViewer.getControl(), true);
614:                    fPropertiesViewer.removeFilter(fErrorElementFilter);
615:                    refreshPropertiesViewer(true);
616:                    properties.setProperty(key, element.getValue());
617:                } else if (fPreErrorKey == null) {
618:                    fErrorElement = element;
619:                    fPreErrorKey = oldKey;
620:                    setEnabled(fPropertiesViewer.getControl(), false);
621:                    fPropertiesViewer.addFilter(fErrorElementFilter);
622:                }
623:            }
624:
625:            private String getErrorMessage(String error, String suggestion) {
626:                StringBuffer sb = new StringBuffer(error);
627:                if (suggestion != null) {
628:                    sb
629:                            .append(PDEUIMessages.ExternalizeStringsWizardPage_keySuggested);
630:                    sb.append(suggestion);
631:                }
632:                return sb.toString();
633:            }
634:
635:            public Object[] getChangeFiles() {
636:                return fInputViewer.getCheckedElements();
637:            }
638:
639:            private boolean hasCheckedElements() {
640:                return fInputViewer.getCheckedElements().length > 0;
641:            }
642:
643:            private void setEnabled(Control exception, boolean enabled) {
644:                if (!exception.equals(fInputViewer.getControl()))
645:                    fInputViewer.getControl().setEnabled(enabled);
646:                if (!exception.equals(fPropertiesViewer.getControl()))
647:                    fPropertiesViewer.getControl().setEnabled(enabled);
648:                if (!exception.equals(fLocalizationText))
649:                    fLocalizationText.setEnabled(enabled);
650:                if (!exception.equals(fSelectAll))
651:                    fSelectAll.setEnabled(enabled);
652:                if (!exception.equals(fDeselectAll))
653:                    fDeselectAll.setEnabled(enabled);
654:            }
655:
656:            public void setPageComplete(boolean complete) {
657:                super .setPageComplete(complete);
658:                // if the page is ready to be completed set the selection on the processor so it knows
659:                // what work needs to be done
660:                if (complete)
661:                    ((ExternalizeStringsProcessor) ((PDERefactor) getRefactoring())
662:                            .getProcessor()).setChangeFiles(fInputViewer
663:                            .getCheckedElements());
664:            }
665:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.