View | Details | Raw Unified | Return to bug 198310 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/pde/internal/ui/wizards/tools/OrganizeManifest.java (-1 / +1 lines)
Lines 298-304 Link Here
298
		HostSpecification hostSpec = bundleDesc.getHost();
298
		HostSpecification hostSpec = bundleDesc.getHost();
299
		if (hostSpec != null) {
299
		if (hostSpec != null) {
300
			BundleDescription[] hosts = hostSpec.getHosts();
300
			BundleDescription[] hosts = hostSpec.getHosts();
301
			for (int i = 0; i < hosts.length; i++) {
301
			for (int i = 0; hosts != null && i < hosts.length; i++) {
302
				IPluginModelBase hostModel = PluginRegistry.findModel(hosts[i]);
302
				IPluginModelBase hostModel = PluginRegistry.findModel(hosts[i]);
303
				if (hostModel != null) {
303
				if (hostModel != null) {
304
					findTranslatedXMLStrings(getTextModel(hostModel, false), list);
304
					findTranslatedXMLStrings(getTextModel(hostModel, false), list);
(-)src/org/eclipse/pde/internal/ui/wizards/tools/OrganizeManifestsWizard.java (-1 / +1 lines)
Lines 21-27 Link Here
21
	private OrganizeManifestsWizardPage fMainPage;
21
	private OrganizeManifestsWizardPage fMainPage;
22
	
22
	
23
	public OrganizeManifestsWizard(PDERefactor refactoring) {
23
	public OrganizeManifestsWizard(PDERefactor refactoring) {
24
		super(refactoring, RefactoringWizard.DIALOG_BASED_USER_INTERFACE);
24
		super(refactoring, WIZARD_BASED_USER_INTERFACE);
25
		setNeedsProgressMonitor(true);
25
		setNeedsProgressMonitor(true);
26
		setWindowTitle(PDEUIMessages.OrganizeManifestsWizard_title);
26
		setWindowTitle(PDEUIMessages.OrganizeManifestsWizard_title);
27
		setDialogSettings(PDEPlugin.getDefault().getDialogSettings());
27
		setDialogSettings(PDEPlugin.getDefault().getDialogSettings());
(-)src/org/eclipse/pde/internal/ui/PDEUIMessages.java (+4 lines)
Lines 71-76 Link Here
71
71
72
	public static String EclipsePluginValidationOperation_pluginMissing;
72
	public static String EclipsePluginValidationOperation_pluginMissing;
73
73
74
	public static String ExternalizeStringsOperation_pluginChangeName;
75
76
	public static String ExternalizeStringsProcessor_errorMessage;
77
74
	public static String JavaArgumentsTab_appendLauncherIni;
78
	public static String JavaArgumentsTab_appendLauncherIni;
75
79
76
	public static String OrganizeManifestsProcessor_invalidParam;
80
	public static String OrganizeManifestsProcessor_invalidParam;
(-)src/org/eclipse/pde/internal/ui/pderesources.properties (+2 lines)
Lines 584-591 Link Here
584
ExternalizeStringsWizardPage_localizationLabel=&Localization:
584
ExternalizeStringsWizardPage_localizationLabel=&Localization:
585
ExternalizeStringsWizardPage_propertiesLabel=Strings to externalize:
585
ExternalizeStringsWizardPage_propertiesLabel=Strings to externalize:
586
ExternalizeStringsWizardPage_sourceLabel=Source:
586
ExternalizeStringsWizardPage_sourceLabel=Source:
587
ExternalizeStringsProcessor_errorMessage=The files to change have not been set on the ExternalizeStringsProcessor
587
ExternalizeStringsWizardPage_keyEmptyError=New key may not be empty
588
ExternalizeStringsWizardPage_keyEmptyError=New key may not be empty
588
ExternalizeStringsWizardPage_keyCommentError=New key may not begin with #, ! or % characters
589
ExternalizeStringsWizardPage_keyCommentError=New key may not begin with #, ! or % characters
590
ExternalizeStringsOperation_pluginChangeName=Externalize Strings for {0}
589
ExternalizeStringsWizardPage_keyError=New key may not contain : or = " " (space) characters
591
ExternalizeStringsWizardPage_keyError=New key may not contain : or = " " (space) characters
590
ExternalizeStringsWizardPage_value=Value
592
ExternalizeStringsWizardPage_value=Value
591
ExternalizeStringsWizardPage_subKey=Substitution Key
593
ExternalizeStringsWizardPage_subKey=Substitution Key
(-)src/org/eclipse/pde/internal/ui/nls/ExternalizeStringsWizard.java (-19 / +7 lines)
Lines 10-45 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.nls;
11
package org.eclipse.pde.internal.ui.nls;
12
12
13
import java.lang.reflect.InvocationTargetException;
13
import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
14
15
import org.eclipse.jface.wizard.Wizard;
16
import org.eclipse.pde.internal.ui.PDEPluginImages;
14
import org.eclipse.pde.internal.ui.PDEPluginImages;
17
import org.eclipse.pde.internal.ui.PDEUIMessages;
15
import org.eclipse.pde.internal.ui.PDEUIMessages;
16
import org.eclipse.pde.internal.ui.refactoring.PDERefactor;
18
17
19
public class ExternalizeStringsWizard extends Wizard {
18
public class ExternalizeStringsWizard extends RefactoringWizard {
20
	private ExternalizeStringsWizardPage page1;
19
	private ExternalizeStringsWizardPage page1;
21
	private ModelChangeTable fModelChangeTable;
20
	private ModelChangeTable fModelChangeTable;
22
21
23
	public ExternalizeStringsWizard(ModelChangeTable changeTable) {
22
	public ExternalizeStringsWizard(ModelChangeTable changeTable, PDERefactor refactoring) {
23
		super(refactoring, WIZARD_BASED_USER_INTERFACE);
24
		setWindowTitle(PDEUIMessages.ExternalizeStringsWizard_title);
24
		setWindowTitle(PDEUIMessages.ExternalizeStringsWizard_title);
25
		setDefaultPageImageDescriptor(PDEPluginImages.DESC_EXTSTR_WIZ);
25
		setDefaultPageImageDescriptor(PDEPluginImages.DESC_EXTSTR_WIZ);
26
		setNeedsProgressMonitor(true);
26
		setNeedsProgressMonitor(true);
27
		fModelChangeTable = changeTable;
27
		fModelChangeTable = changeTable;
28
	}
28
	}
29
	
29
	protected void addUserInputPages() {
30
	public boolean performFinish() {
30
		setDefaultPageTitle( getRefactoring().getName() );
31
		try {
32
			getContainer().run(false, false,
33
					new ExternalizeStringsOperation(page1.getChangeFiles()));
34
		} catch (InvocationTargetException e) {
35
			return false;
36
		} catch (InterruptedException e) {
37
			return false;
38
		}
39
		return true;
40
	}
41
	
42
	public void addPages() {
43
		page1 = new ExternalizeStringsWizardPage(fModelChangeTable);
31
		page1 = new ExternalizeStringsWizardPage(fModelChangeTable);
44
		addPage(page1);
32
		addPage(page1);
45
	}
33
	}
(-)src/org/eclipse/pde/internal/ui/nls/ExternalizeStringsWizardPage.java (-2 / +12 lines)
Lines 37-43 Link Here
37
import org.eclipse.jface.viewers.TextCellEditor;
37
import org.eclipse.jface.viewers.TextCellEditor;
38
import org.eclipse.jface.viewers.Viewer;
38
import org.eclipse.jface.viewers.Viewer;
39
import org.eclipse.jface.viewers.ViewerFilter;
39
import org.eclipse.jface.viewers.ViewerFilter;
40
import org.eclipse.jface.wizard.WizardPage;
40
import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
41
import org.eclipse.pde.core.plugin.IPluginModelBase;
41
import org.eclipse.pde.core.plugin.IPluginModelBase;
42
import org.eclipse.pde.internal.ui.IHelpContextIds;
42
import org.eclipse.pde.internal.ui.IHelpContextIds;
43
import org.eclipse.pde.internal.ui.PDEPlugin;
43
import org.eclipse.pde.internal.ui.PDEPlugin;
Lines 48-53 Link Here
48
import org.eclipse.pde.internal.ui.editor.text.IColorManager;
48
import org.eclipse.pde.internal.ui.editor.text.IColorManager;
49
import org.eclipse.pde.internal.ui.editor.text.ManifestConfiguration;
49
import org.eclipse.pde.internal.ui.editor.text.ManifestConfiguration;
50
import org.eclipse.pde.internal.ui.editor.text.XMLConfiguration;
50
import org.eclipse.pde.internal.ui.editor.text.XMLConfiguration;
51
import org.eclipse.pde.internal.ui.refactoring.PDERefactor;
51
import org.eclipse.pde.internal.ui.wizards.ListUtil;
52
import org.eclipse.pde.internal.ui.wizards.ListUtil;
52
import org.eclipse.swt.SWT;
53
import org.eclipse.swt.SWT;
53
import org.eclipse.swt.custom.SashForm;
54
import org.eclipse.swt.custom.SashForm;
Lines 70-76 Link Here
70
import org.eclipse.ui.PlatformUI;
71
import org.eclipse.ui.PlatformUI;
71
import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer;
72
import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer;
72
73
73
public class ExternalizeStringsWizardPage extends WizardPage {
74
public class ExternalizeStringsWizardPage extends UserInputWizardPage {
74
75
75
	public static final String PAGE_NAME = "ExternalizeStringsWizardPage"; //$NON-NLS-1$
76
	public static final String PAGE_NAME = "ExternalizeStringsWizardPage"; //$NON-NLS-1$
76
	
77
	
Lines 573-576 Link Here
573
    	if (!exception.equals(fDeselectAll))
574
    	if (!exception.equals(fDeselectAll))
574
    		fDeselectAll.setEnabled(enabled);
575
    		fDeselectAll.setEnabled(enabled);
575
    }
576
    }
577
    
578
    public void setPageComplete(boolean complete) {
579
    	super.setPageComplete(complete);
580
    	// if the page is ready to be completed set the selection on the processor so it knows
581
    	// what work needs to be done
582
    	if (complete)
583
			((ExternalizeStringsProcessor)((PDERefactor)getRefactoring()).getProcessor()).
584
				setChangeFiles(fInputViewer.getCheckedElements());
585
    }
576
}
586
}
(-)src/org/eclipse/pde/internal/ui/nls/ExternalizeStringsOperation.java (-48 / +62 lines)
Lines 10-38 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.nls;
11
package org.eclipse.pde.internal.ui.nls;
12
12
13
import java.io.ByteArrayInputStream;
14
import java.io.IOException;
15
import java.lang.reflect.InvocationTargetException;
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.HashMap;
16
import java.util.Iterator;
15
import java.util.Iterator;
17
16
18
import org.eclipse.core.filebuffers.FileBuffers;
17
import org.eclipse.core.filebuffers.FileBuffers;
19
import org.eclipse.core.filebuffers.ITextFileBuffer;
18
import org.eclipse.core.filebuffers.ITextFileBuffer;
20
import org.eclipse.core.filebuffers.ITextFileBufferManager;
19
import org.eclipse.core.filebuffers.ITextFileBufferManager;
21
import org.eclipse.core.resources.IContainer;
20
import org.eclipse.core.filebuffers.LocationKind;
22
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.resources.IFile;
23
import org.eclipse.core.resources.IFolder;
24
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.NullProgressMonitor;
27
import org.eclipse.jface.text.BadLocationException;
28
import org.eclipse.jface.text.IDocument;
24
import org.eclipse.jface.text.IDocument;
29
import org.eclipse.jface.text.TextUtilities;
25
import org.eclipse.jface.text.TextUtilities;
26
import org.eclipse.ltk.core.refactoring.CompositeChange;
27
import org.eclipse.ltk.core.refactoring.TextFileChange;
30
import org.eclipse.osgi.util.NLS;
28
import org.eclipse.osgi.util.NLS;
31
import org.eclipse.pde.core.IBaseModel;
29
import org.eclipse.pde.core.IBaseModel;
32
import org.eclipse.pde.core.plugin.IPluginModelBase;
30
import org.eclipse.pde.core.plugin.IPluginModelBase;
33
import org.eclipse.pde.internal.core.ibundle.IBundle;
31
import org.eclipse.pde.internal.core.ibundle.IBundle;
34
import org.eclipse.pde.internal.core.ibundle.IBundlePluginModel;
32
import org.eclipse.pde.internal.core.ibundle.IBundlePluginModel;
35
import org.eclipse.pde.internal.core.util.CoreUtility;
33
import org.eclipse.pde.internal.ui.PDEUIMessages;
36
import org.eclipse.pde.internal.ui.util.ModelModification;
34
import org.eclipse.pde.internal.ui.util.ModelModification;
37
import org.eclipse.pde.internal.ui.util.PDEModelUtility;
35
import org.eclipse.pde.internal.ui.util.PDEModelUtility;
38
import org.eclipse.text.edits.InsertEdit;
36
import org.eclipse.text.edits.InsertEdit;
Lines 44-91 Link Here
44
public class ExternalizeStringsOperation extends WorkspaceModifyOperation {
42
public class ExternalizeStringsOperation extends WorkspaceModifyOperation {
45
43
46
	private Object[] fChangeFiles;
44
	private Object[] fChangeFiles;
45
	private CompositeChange fParentChange;
46
	private HashMap fCompositeChanges;
47
	private HashMap fFileEdits;
47
	
48
	
48
	public ExternalizeStringsOperation(Object[] changeFiles) {
49
	public ExternalizeStringsOperation(Object[] changeFiles, CompositeChange parentChange) {
49
		fChangeFiles = changeFiles;
50
		fChangeFiles = changeFiles;
51
		fParentChange = parentChange;
52
		fCompositeChanges = new HashMap();
53
		fFileEdits = new HashMap();
50
	}
54
	}
51
	protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
55
	protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
52
		for (int i = 0; i < fChangeFiles.length; i++) {
56
		for (int i = 0; i < fChangeFiles.length; i++) {
53
			if (fChangeFiles[i] instanceof ModelChangeFile) {
57
			if (fChangeFiles[i] instanceof ModelChangeFile) {
54
				ModelChangeFile changeFile = (ModelChangeFile)fChangeFiles[i];
58
				ModelChangeFile changeFile = (ModelChangeFile)fChangeFiles[i];
59
				CompositeChange pluginChange = getChangeForPlugin(changeFile.getModel().getParentModel().getPluginBase().getId());
55
				ModelChange change = changeFile.getModel();
60
				ModelChange change = changeFile.getModel();
56
				IFile pFile = change.getPropertiesFile();
61
				IFile pFile = change.getPropertiesFile();
57
				checkPropertiesFile(pFile);
62
				// if the properties file does not exist and we have not already made a TextFileChange
63
				// for it create the Change and insert a comment
64
				if (!pFile.exists() && !fFileEdits.containsKey(pFile))
65
					getEditForFile(pFile, pluginChange).addChild(new InsertEdit(0, getPropertiesFileComment(pFile)));
58
				if (!change.localizationSet())
66
				if (!change.localizationSet())
59
					addBundleLocalization(change, monitor);
67
					addBundleLocalization(change, monitor, pluginChange);
60
				
68
				
61
				ITextFileBufferManager pManager = FileBuffers.getTextFileBufferManager();
69
				ITextFileBufferManager pManager = FileBuffers.getTextFileBufferManager();
62
				try {
70
				try {
63
					pManager.connect(pFile.getFullPath(), monitor);
71
					pManager.connect(pFile.getFullPath(), LocationKind.IFILE, monitor);
64
					ITextFileBuffer pBuffer = pManager.getTextFileBuffer(pFile.getFullPath());
72
					ITextFileBuffer pBuffer = pManager.getTextFileBuffer(pFile.getFullPath(), LocationKind.IFILE);
65
					IDocument pDoc = pBuffer.getDocument();
73
					IDocument pDoc = pBuffer.getDocument();
66
					MultiTextEdit pEdit = new MultiTextEdit();
74
					MultiTextEdit pEdit = getEditForFile(pFile, pluginChange);
67
					
75
					
68
					doReplace(changeFile, pDoc, pEdit, monitor);
76
					doReplace(changeFile, pDoc, pEdit, monitor, pluginChange);
69
					
70
					pEdit.apply(pDoc);
71
					pBuffer.commit(monitor, true);
72
					
77
					
73
				} catch (MalformedTreeException e) {
78
				} catch (MalformedTreeException e) {
74
				} catch (BadLocationException e) {
75
				} finally {
79
				} finally {
76
					pManager.disconnect(pFile.getFullPath(), monitor);
80
					pManager.disconnect(pFile.getFullPath(), LocationKind.IFILE, monitor);
77
				}
81
				}
78
			}
82
			}
79
		}
83
		}
80
	}
84
	}
81
	private void doReplace(ModelChangeFile changeFile, IDocument pDoc, MultiTextEdit pEdit, IProgressMonitor monitor) throws CoreException {
85
	private CompositeChange getChangeForPlugin(String pluginName) {
86
		if (fCompositeChanges.containsKey(pluginName))
87
			return (CompositeChange) fCompositeChanges.get(pluginName);
88
		CompositeChange result = new CompositeChange(NLS.bind(PDEUIMessages.ExternalizeStringsOperation_pluginChangeName, pluginName));
89
		fCompositeChanges.put(pluginName, result);
90
		fParentChange.add(result);
91
		return result;
92
	}
93
	private MultiTextEdit getEditForFile(IFile file, CompositeChange parentChange) {
94
		if (fFileEdits.containsKey(file))
95
			return (MultiTextEdit) fFileEdits.get(file);
96
		MultiTextEdit edit = new MultiTextEdit();
97
		TextFileChange change = new TextFileChange(file.getName(), file);
98
		change.setEdit(edit);
99
		// mark a plugin.xml or a fragment.xml as PLUGIN2 type so they will be compared
100
		// with the PluginContentMergeViewer
101
		String textType = file.getName().equals("plugin.xml") || //$NON-NLS-1$
102
				file.getName().equals("fragment.xml") ? //$NON-NLS-1$
103
				"PLUGIN2" : file.getFileExtension(); //$NON-NLS-1$
104
		change.setTextType(textType);
105
		parentChange.add(change);
106
		fFileEdits.put(file, edit);
107
		return edit;
108
	}
109
	private void doReplace(ModelChangeFile changeFile, IDocument pDoc, MultiTextEdit pEdit, IProgressMonitor monitor, CompositeChange parentChange) throws CoreException {
82
		IFile uFile = changeFile.getFile();
110
		IFile uFile = changeFile.getFile();
83
		ITextFileBufferManager uManager = FileBuffers.getTextFileBufferManager();
84
		try {
111
		try {
85
			uManager.connect(uFile.getFullPath(), monitor);
112
			MultiTextEdit uEdit = getEditForFile(uFile, parentChange);
86
			ITextFileBuffer uBuffer = uManager.getTextFileBuffer(uFile.getFullPath());
87
			IDocument uDoc = uBuffer.getDocument();
88
			MultiTextEdit uEdit = new MultiTextEdit();
89
			
113
			
90
			Iterator iter = changeFile.getChanges().iterator();
114
			Iterator iter = changeFile.getChanges().iterator();
91
			
115
			
Lines 98-118 Link Here
98
					pEdit.addChild(getPropertiesInsertEdit(pDoc, changeElement));
122
					pEdit.addChild(getPropertiesInsertEdit(pDoc, changeElement));
99
				}
123
				}
100
			}
124
			}
101
			uEdit.apply(uDoc);
102
			uBuffer.commit(monitor, true);
103
			
104
		} catch (MalformedTreeException e) {
125
		} catch (MalformedTreeException e) {
105
		} catch (BadLocationException e) {
106
		} finally {
107
			uManager.disconnect(uFile.getFullPath(), monitor);
108
		}
126
		}
109
 	}
127
 	}
110
	
128
	
111
	private void addBundleLocalization(ModelChange change, IProgressMonitor mon) {
129
	private void addBundleLocalization(ModelChange change, IProgressMonitor mon, CompositeChange parent) {
112
		IPluginModelBase base = change.getParentModel();
130
		IPluginModelBase base = change.getParentModel();
113
		IFile manifest = base.getUnderlyingResource().getProject().getFile(PDEModelUtility.F_MANIFEST_FP);
131
		IFile manifest = base.getUnderlyingResource().getProject().getFile(PDEModelUtility.F_MANIFEST_FP);
132
		// if the edit for this manifest file is in the HashMap, then we must have added
133
		// the localization already since it is checked first (this must be the second or subsequent
134
		// change to the manifest for this plug-in)
135
		if (fFileEdits.containsKey(manifest))
136
			return;
114
		final String localiz = change.getBundleLocalization();
137
		final String localiz = change.getBundleLocalization();
115
		PDEModelUtility.modifyModel(new ModelModification(manifest) {
138
		TextFileChange[] result = PDEModelUtility.changesForModelModication(new ModelModification(manifest) {
116
			protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws CoreException {
139
			protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws CoreException {
117
				if (model instanceof IBundlePluginModel) {
140
				if (model instanceof IBundlePluginModel) {
118
					IBundlePluginModel bundleModel = (IBundlePluginModel) model;
141
					IBundlePluginModel bundleModel = (IBundlePluginModel) model;
Lines 121-126 Link Here
121
				}
144
				}
122
			}
145
			}
123
		}, mon);
146
		}, mon);
147
		// this model change just adds localization to the manifest, so we will only have one change
148
		// with one edit
149
		if (result.length > 0 && result[0] != null)
150
			getEditForFile(manifest, parent).addChild(result[0].getEdit());
124
	}
151
	}
125
	
152
	
126
	public static InsertEdit getPropertiesInsertEdit(IDocument doc, ModelChangeElement element) {
153
	public static InsertEdit getPropertiesInsertEdit(IDocument doc, ModelChangeElement element) {
Lines 132-151 Link Here
132
		return new InsertEdit(doc.getLength(), sb.toString());
159
		return new InsertEdit(doc.getLength(), sb.toString());
133
	}
160
	}
134
	
161
	
135
	public static void checkPropertiesFile(IFile file) {
162
	public static String getPropertiesFileComment(IFile file) {
136
		if (!file.exists()) {
163
		return NLS.bind("#Properties file for {0}", file.getProject().getName()); //$NON-NLS-1$
137
			String propertiesFileComment = NLS.bind("#Properties file for {0}", file.getProject().getName()); //$NON-NLS-1$
138
			ByteArrayInputStream pStream = new ByteArrayInputStream(propertiesFileComment.getBytes());
139
			try {
140
				IContainer container = file.getParent();
141
				if (!container.exists())
142
					// project will exists, therefore we can assume if !IContainer.exist(), the object is an IFolder
143
					CoreUtility.createFolder((IFolder)container);
144
				file.create(pStream, true, new NullProgressMonitor());
145
				pStream.close();
146
			} catch (CoreException e1) {
147
			} catch (IOException e) {
148
			}
149
		}
150
	}
164
	}
151
 }
165
 }
(-)src/org/eclipse/pde/internal/ui/nls/GetNonExternalizedStringsAction.java (-9 / +11 lines)
Lines 15-24 Link Here
15
import org.eclipse.jface.action.IAction;
15
import org.eclipse.jface.action.IAction;
16
import org.eclipse.jface.dialogs.MessageDialog;
16
import org.eclipse.jface.dialogs.MessageDialog;
17
import org.eclipse.jface.viewers.ISelection;
17
import org.eclipse.jface.viewers.ISelection;
18
import org.eclipse.jface.wizard.WizardDialog;
18
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
19
import org.eclipse.pde.internal.ui.PDEPlugin;
19
import org.eclipse.pde.internal.ui.PDEPlugin;
20
import org.eclipse.pde.internal.ui.PDEUIMessages;
20
import org.eclipse.pde.internal.ui.PDEUIMessages;
21
import org.eclipse.swt.custom.BusyIndicator;
21
import org.eclipse.pde.internal.ui.refactoring.PDERefactor;
22
import org.eclipse.ui.IWorkbenchWindow;
22
import org.eclipse.ui.IWorkbenchWindow;
23
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
23
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
24
import org.eclipse.ui.PlatformUI;
24
import org.eclipse.ui.PlatformUI;
Lines 41-53 Link Here
41
				return;
41
				return;
42
			ModelChangeTable changeTable = runnable.getChangeTable();
42
			ModelChangeTable changeTable = runnable.getChangeTable();
43
			if (!changeTable.isEmpty()) {
43
			if (!changeTable.isEmpty()) {
44
				ExternalizeStringsWizard wizard = new ExternalizeStringsWizard(changeTable);
44
				ExternalizeStringsProcessor processor = new ExternalizeStringsProcessor();
45
				final WizardDialog dialog = new WizardDialog(PDEPlugin.getActiveWorkbenchShell(), wizard);
45
				PDERefactor refactor = new PDERefactor(processor);
46
				BusyIndicator.showWhile(PDEPlugin.getActiveWorkbenchShell().getDisplay(), new Runnable() {
46
				ExternalizeStringsWizard wizard = new ExternalizeStringsWizard(changeTable, refactor);
47
					public void run() {
47
				RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation( wizard );
48
						dialog.open();
48
				
49
					}
49
			    try {
50
				});
50
			      op.run( PDEPlugin.getActiveWorkbenchShell(), "" ); //$NON-NLS-1$
51
			    } catch( final InterruptedException irex ) {
52
			    }
51
			} else
53
			} else
52
				MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), 
54
				MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), 
53
						PDEUIMessages.GetNonExternalizedStringsAction_allExternalizedTitle, 
55
						PDEUIMessages.GetNonExternalizedStringsAction_allExternalizedTitle, 
(-)src/org/eclipse/pde/internal/ui/correction/ExternalizeResolution.java (-4 / +28 lines)
Lines 10-23 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.correction;
11
package org.eclipse.pde.internal.ui.correction;
12
12
13
import java.io.ByteArrayInputStream;
14
import java.io.IOException;
15
13
import org.eclipse.core.filebuffers.FileBuffers;
16
import org.eclipse.core.filebuffers.FileBuffers;
14
import org.eclipse.core.filebuffers.ITextFileBuffer;
17
import org.eclipse.core.filebuffers.ITextFileBuffer;
15
import org.eclipse.core.filebuffers.ITextFileBufferManager;
18
import org.eclipse.core.filebuffers.ITextFileBufferManager;
19
import org.eclipse.core.filebuffers.LocationKind;
20
import org.eclipse.core.resources.IContainer;
16
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.resources.IFile;
22
import org.eclipse.core.resources.IFolder;
17
import org.eclipse.core.resources.IMarker;
23
import org.eclipse.core.resources.IMarker;
18
import org.eclipse.core.resources.IProject;
24
import org.eclipse.core.resources.IProject;
19
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.IProgressMonitor;
27
import org.eclipse.core.runtime.NullProgressMonitor;
21
import org.eclipse.jface.text.BadLocationException;
28
import org.eclipse.jface.text.BadLocationException;
22
import org.eclipse.jface.text.IDocument;
29
import org.eclipse.jface.text.IDocument;
23
import org.eclipse.osgi.util.NLS;
30
import org.eclipse.osgi.util.NLS;
Lines 26-31 Link Here
26
import org.eclipse.pde.internal.core.PDEManager;
33
import org.eclipse.pde.internal.core.PDEManager;
27
import org.eclipse.pde.internal.core.ibundle.IBundle;
34
import org.eclipse.pde.internal.core.ibundle.IBundle;
28
import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase;
35
import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase;
36
import org.eclipse.pde.internal.core.util.CoreUtility;
29
import org.eclipse.pde.internal.ui.PDEPlugin;
37
import org.eclipse.pde.internal.ui.PDEPlugin;
30
import org.eclipse.pde.internal.ui.PDEUIMessages;
38
import org.eclipse.pde.internal.ui.PDEUIMessages;
31
import org.eclipse.pde.internal.ui.nls.ExternalizeStringsOperation;
39
import org.eclipse.pde.internal.ui.nls.ExternalizeStringsOperation;
Lines 53-63 Link Here
53
			localization += ModelChange.LOCALIZATION_FILE_SUFFIX;
61
			localization += ModelChange.LOCALIZATION_FILE_SUFFIX;
54
			IProject project = model.getUnderlyingResource().getProject();
62
			IProject project = model.getUnderlyingResource().getProject();
55
			IFile file = project.getFile(localization);
63
			IFile file = project.getFile(localization);
56
			ExternalizeStringsOperation.checkPropertiesFile(file);
64
			checkPropertiesFile(file);
57
			try {
65
			try {
58
				ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
66
				ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
59
				manager.connect(file.getFullPath(), null);
67
				manager.connect(file.getFullPath(), LocationKind.IFILE, null);
60
				ITextFileBuffer buffer = manager.getTextFileBuffer(file.getFullPath());
68
				ITextFileBuffer buffer = manager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
61
				if (buffer.isDirty())
69
				if (buffer.isDirty())
62
					buffer.commit(null, true);
70
					buffer.commit(null, true);
63
				
71
				
Lines 72-78 Link Here
72
				PDEPlugin.log(e);
80
				PDEPlugin.log(e);
73
			} finally {
81
			} finally {
74
				try {
82
				try {
75
					FileBuffers.getTextFileBufferManager().disconnect(file.getFullPath(), null);
83
					FileBuffers.getTextFileBufferManager().disconnect(file.getFullPath(), LocationKind.IFILE, null);
76
				} catch (CoreException e) {
84
				} catch (CoreException e) {
77
					PDEPlugin.log(e);
85
					PDEPlugin.log(e);
78
				}
86
				}
Lines 123-126 Link Here
123
		PDEModelUtility.modifyModel(modification, null);
131
		PDEModelUtility.modifyModel(modification, null);
124
	}
132
	}
125
133
134
	private void checkPropertiesFile(IFile file) {
135
		if (!file.exists()) {
136
			String propertiesFileComment = ExternalizeStringsOperation.getPropertiesFileComment(file);
137
			ByteArrayInputStream pStream = new ByteArrayInputStream(propertiesFileComment.getBytes());
138
			try {
139
				IContainer container = file.getParent();
140
				if (!container.exists())
141
					// project will exists, therefore we can assume if !IContainer.exist(), the object is an IFolder
142
					CoreUtility.createFolder((IFolder)container);
143
				file.create(pStream, true, new NullProgressMonitor());
144
				pStream.close();
145
			} catch (CoreException e1) {
146
			} catch (IOException e) {
147
			}
148
		}
149
	}
126
}
150
}
(-)src/org/eclipse/pde/internal/ui/nls/ExternalizeStringsProcessor.java (+83 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 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
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.nls;
12
13
import java.lang.reflect.InvocationTargetException;
14
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.OperationCanceledException;
18
import org.eclipse.ltk.core.refactoring.Change;
19
import org.eclipse.ltk.core.refactoring.CompositeChange;
20
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
21
import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
22
import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant;
23
import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor;
24
import org.eclipse.ltk.core.refactoring.participants.SharableParticipants;
25
import org.eclipse.pde.internal.ui.PDEUIMessages;
26
27
public class ExternalizeStringsProcessor extends RefactoringProcessor {
28
29
	Object[] fChangeFiles = null;
30
	
31
	public RefactoringStatus checkFinalConditions(IProgressMonitor pm,
32
			CheckConditionsContext context) throws CoreException,
33
			OperationCanceledException {
34
		RefactoringStatus status = new RefactoringStatus();
35
		if (fChangeFiles == null)
36
			status.addFatalError(PDEUIMessages.ExternalizeStringsProcessor_errorMessage);
37
		return status;
38
	}
39
40
	public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
41
			throws CoreException, OperationCanceledException {
42
		return null;
43
	}
44
45
	public Change createChange(IProgressMonitor pm) throws CoreException,
46
			OperationCanceledException {
47
		CompositeChange change = new CompositeChange(""); //$NON-NLS-1$
48
		change.markAsSynthetic();
49
		ExternalizeStringsOperation op = new ExternalizeStringsOperation(fChangeFiles, change);
50
		try {
51
			op.run(pm);
52
		} catch (InvocationTargetException e) {
53
		} catch (InterruptedException e) {
54
		}
55
		return change;
56
	}
57
58
	public Object[] getElements() {
59
		return fChangeFiles;
60
	}
61
62
	public String getIdentifier() {
63
		return getClass().getName();
64
	}
65
66
	public String getProcessorName() {
67
		return PDEUIMessages.ExternalizeStringsWizard_title;
68
	}
69
70
	public boolean isApplicable() throws CoreException {
71
		return true;
72
	}
73
74
	public RefactoringParticipant[] loadParticipants(RefactoringStatus status,
75
			SharableParticipants sharedParticipants) throws CoreException {
76
		return new RefactoringParticipant[0];
77
	}
78
79
	public void setChangeFiles(Object[] changeFiles) {
80
		fChangeFiles = changeFiles;
81
	}
82
83
}

Return to bug 198310