Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 113249
Collapse All | Expand All

(-)src-catalog/org/eclipse/wst/xml/core/internal/catalog/Catalog.java (-4 / +11 lines)
Lines 40-53 Link Here
40
		{
40
		{
41
		}
41
		}
42
42
43
		public synchronized void save()
43
		public synchronized void save() throws IOException
44
		{
44
		{
45
			try
45
			try
46
			{
46
			{
47
				new CatalogWriter().write(Catalog.this, location);
47
				new CatalogWriter().write(Catalog.this, location);
48
			} catch (Exception e)
48
			} catch (IOException e)
49
			{
49
			{
50
				Logger.logException(e);
50
				Logger.logException(e);
51
				throw e;
51
			}
52
			}
52
		}
53
		}
53
	}
54
	}
Lines 71-77 Link Here
71
			 * we've created from plug-in extensions to disk. The 'default'
72
			 * we've created from plug-in extensions to disk. The 'default'
72
			 * catalog is only ever written to disk and never read from disk.
73
			 * catalog is only ever written to disk and never read from disk.
73
			 */
74
			 */
74
			save();
75
			try {
76
				save();
77
			} catch (Exception e) {
78
			}
75
		}
79
		}
76
	}
80
	}
77
81
Lines 202-208 Link Here
202
			 * we've created from plugin extensions to disk. 
206
			 * we've created from plugin extensions to disk. 
203
			 * The 'system' catalog is only ever written to disk and never read from disk.
207
			 * The 'system' catalog is only ever written to disk and never read from disk.
204
			 */
208
			 */
205
			save();
209
			try {
210
				save();
211
			} catch (Exception e) {
212
			}
206
		}
213
		}
207
	}
214
	}
208
215
(-)src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLCatalogResources.properties (-2 / +4 lines)
Lines 100-107 Link Here
100
UI_LABEL_EXPORT_DIALOG_TITLE         = Export XML Catalog Settings
100
UI_LABEL_EXPORT_DIALOG_TITLE         = Export XML Catalog Settings
101
UI_LABEL_EXPORT_DIALOG_HEADING       = Specify XML Catalog File
101
UI_LABEL_EXPORT_DIALOG_HEADING       = Specify XML Catalog File
102
UI_LABEL_EXPORT_DIALOG_MESSAGE       = Specify the file that will used to save the XML Catalog Setting
102
UI_LABEL_EXPORT_DIALOG_MESSAGE       = Specify the file that will used to save the XML Catalog Setting
103
ERROR_SAVING_FILE					 = Error saving file %1
103
ERROR_SAVING_FILE					 = Error saving file {0}
104
UI_LABEL_FILE_IS_READ_ONLY           = File %1 is read only
104
UI_LABEL_FILE_IS_READ_ONLY           = File {0} is read only
105
105
106
EditCatalogEntryDialog_catalogEntryLabel=Catalog Entry
106
EditCatalogEntryDialog_catalogEntryLabel=Catalog Entry
107
EditCatalogEntryDialog_nextCatalogLabel=Next Catalog
107
EditCatalogEntryDialog_nextCatalogLabel=Next Catalog
Lines 109-111 Link Here
109
UI_BUTTON_MENU_BROWSE_FILE_SYSTEM=File System...
109
UI_BUTTON_MENU_BROWSE_FILE_SYSTEM=File System...
110
UI_LABEL_SELECT_FILE_FILTER_CONTROL=Files of type:
110
UI_LABEL_SELECT_FILE_FILTER_CONTROL=Files of type:
111
UI_TEXT_SELECT_FILE_FILTER_CONTROL=All Supported Files
111
UI_TEXT_SELECT_FILE_FILTER_CONTROL=All Supported Files
112
UI_OVERWRITE_FILE_DIALOG_TITLE=Overwrite
113
UI_OVERWRITE_FILE_DIALOG_TEXT=Overwrite existing file?
(-)src-catalog/org/eclipse/wst/xml/ui/internal/catalog/XMLCatalogMessages.java (+2 lines)
Lines 120-125 Link Here
120
	public static String UI_BUTTON_MENU_BROWSE_FILE_SYSTEM;
120
	public static String UI_BUTTON_MENU_BROWSE_FILE_SYSTEM;
121
	public static String UI_LABEL_SELECT_FILE_FILTER_CONTROL;
121
	public static String UI_LABEL_SELECT_FILE_FILTER_CONTROL;
122
	public static String UI_TEXT_SELECT_FILE_FILTER_CONTROL;
122
	public static String UI_TEXT_SELECT_FILE_FILTER_CONTROL;
123
	public static String UI_OVERWRITE_FILE_DIALOG_TITLE;
124
	public static String UI_OVERWRITE_FILE_DIALOG_TEXT;
123
125
124
126
125
127
(-)src-catalog/org/eclipse/wst/xml/ui/internal/catalog/AdvancedOptionsDialog.java (-39 / +145 lines)
Lines 13-18 Link Here
13
package org.eclipse.wst.xml.ui.internal.catalog;
13
package org.eclipse.wst.xml.ui.internal.catalog;
14
14
15
import java.io.ByteArrayInputStream;
15
import java.io.ByteArrayInputStream;
16
import java.io.File;
16
17
17
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.IProject;
19
import org.eclipse.core.resources.IProject;
Lines 24-42 Link Here
24
import org.eclipse.jface.dialogs.Dialog;
25
import org.eclipse.jface.dialogs.Dialog;
25
import org.eclipse.jface.dialogs.ErrorDialog;
26
import org.eclipse.jface.dialogs.ErrorDialog;
26
import org.eclipse.jface.dialogs.IDialogConstants;
27
import org.eclipse.jface.dialogs.IDialogConstants;
28
import org.eclipse.jface.dialogs.MessageDialog;
27
import org.eclipse.jface.window.Window;
29
import org.eclipse.jface.window.Window;
28
import org.eclipse.osgi.util.NLS;
30
import org.eclipse.osgi.util.NLS;
29
import org.eclipse.swt.SWT;
31
import org.eclipse.swt.SWT;
30
import org.eclipse.swt.events.SelectionAdapter;
32
import org.eclipse.swt.events.SelectionAdapter;
31
import org.eclipse.swt.events.SelectionEvent;
33
import org.eclipse.swt.events.SelectionEvent;
32
import org.eclipse.swt.events.SelectionListener;
34
import org.eclipse.swt.events.SelectionListener;
35
import org.eclipse.swt.graphics.Point;
36
import org.eclipse.swt.graphics.Rectangle;
33
import org.eclipse.swt.layout.GridData;
37
import org.eclipse.swt.layout.GridData;
34
import org.eclipse.swt.layout.GridLayout;
38
import org.eclipse.swt.layout.GridLayout;
35
import org.eclipse.swt.widgets.Button;
39
import org.eclipse.swt.widgets.Button;
36
import org.eclipse.swt.widgets.Composite;
40
import org.eclipse.swt.widgets.Composite;
37
import org.eclipse.swt.widgets.Control;
41
import org.eclipse.swt.widgets.Control;
38
import org.eclipse.swt.widgets.Display;
42
import org.eclipse.swt.widgets.Display;
43
import org.eclipse.swt.widgets.FileDialog;
39
import org.eclipse.swt.widgets.Label;
44
import org.eclipse.swt.widgets.Label;
45
import org.eclipse.swt.widgets.Menu;
46
import org.eclipse.swt.widgets.MenuItem;
40
import org.eclipse.swt.widgets.Shell;
47
import org.eclipse.swt.widgets.Shell;
41
import org.eclipse.ui.dialogs.SaveAsDialog;
48
import org.eclipse.ui.dialogs.SaveAsDialog;
42
import org.eclipse.wst.common.ui.internal.dialogs.SelectSingleFileDialog;
49
import org.eclipse.wst.common.ui.internal.dialogs.SelectSingleFileDialog;
Lines 46-51 Link Here
46
53
47
public class AdvancedOptionsDialog extends Dialog {
54
public class AdvancedOptionsDialog extends Dialog {
48
	protected ICatalog workingUserCatalog;
55
	protected ICatalog workingUserCatalog;
56
	
57
	private int browseAt;
58
59
	private Button importButton;
60
61
	private Button exportButton;
62
	
63
	private Menu menu;
64
	
65
	public static final int NO_OPERATION = 0;
66
	
67
	public static final int BROWSE_FILE_SYSTEM = 1;
68
	
69
	public static final int BROWSE_WORKSPACE = 2;
70
	
49
71
50
	public AdvancedOptionsDialog(Shell parentShell, ICatalog workingUserCatalog) {
72
	public AdvancedOptionsDialog(Shell parentShell, ICatalog workingUserCatalog) {
51
		super(parentShell);
73
		super(parentShell);
Lines 88-97 Link Here
88
		buttonGroup.setLayout(gridLayout);
110
		buttonGroup.setLayout(gridLayout);
89
		buttonGroup.setLayoutData(createGridData());
111
		buttonGroup.setLayoutData(createGridData());
90
112
91
		Button importButton = new Button(buttonGroup, SWT.PUSH | SWT.CENTER);
113
		importButton = new Button(buttonGroup, SWT.PUSH | SWT.CENTER);
92
		importButton.setText("  " + XMLCatalogMessages.UI_BUTTON_IMPORT + "  "); //$NON-NLS-1$ //$NON-NLS-2$
114
		importButton.setText("  " + XMLCatalogMessages.UI_BUTTON_IMPORT + "  "); //$NON-NLS-1$ //$NON-NLS-2$
93
115
94
		Button exportButton = new Button(buttonGroup, SWT.PUSH | SWT.CENTER);
116
		exportButton = new Button(buttonGroup, SWT.PUSH | SWT.CENTER);
95
		exportButton.setText("  " + XMLCatalogMessages.UI_BUTTON_EXPORT + "  "); //$NON-NLS-1$ //$NON-NLS-2$
117
		exportButton.setText("  " + XMLCatalogMessages.UI_BUTTON_EXPORT + "  "); //$NON-NLS-1$ //$NON-NLS-2$
96
118
97
		placeHolder = new Composite(buttonComposite, SWT.NONE);
119
		placeHolder = new Composite(buttonComposite, SWT.NONE);
Lines 100-106 Link Here
100
		// add importButton listener
122
		// add importButton listener
101
		SelectionListener importButtonSelectionListener = new SelectionAdapter() {
123
		SelectionListener importButtonSelectionListener = new SelectionAdapter() {
102
			public void widgetSelected(SelectionEvent e) {
124
			public void widgetSelected(SelectionEvent e) {
103
				invokeImportDialog();
125
				String file = null;
126
				Point ptBrowse = importButton.getLocation();
127
				Rectangle rcBrowse = importButton.getBounds();
128
				ptBrowse.y += rcBrowse.height;
129
				ptBrowse = importButton.getParent().toDisplay(ptBrowse);
130
				browseAt = NO_OPERATION;
131
				show_menu(ptBrowse);
132
				switch(browseAt) {
133
					case BROWSE_FILE_SYSTEM: file = invokeFileSystemImportDialog(); break;
134
					case BROWSE_WORKSPACE: file = invokeWorkspaceImportDialog();
135
				}
136
				if(file != null) {
137
					importCatalog(file);
138
				}
104
			}
139
			}
105
		};
140
		};
106
		importButton.addSelectionListener(importButtonSelectionListener);
141
		importButton.addSelectionListener(importButtonSelectionListener);
Lines 108-118 Link Here
108
		// add exportButton listener
143
		// add exportButton listener
109
		SelectionListener exportButtonSelectionListener = new SelectionAdapter() {
144
		SelectionListener exportButtonSelectionListener = new SelectionAdapter() {
110
			public void widgetSelected(SelectionEvent e) {
145
			public void widgetSelected(SelectionEvent e) {
111
				invokeExportDialog();
146
				String file = null;
147
				Point ptBrowse = exportButton.getLocation();
148
				Rectangle rcBrowse = exportButton.getBounds();
149
				ptBrowse.y += rcBrowse.height;
150
				ptBrowse = exportButton.getParent().toDisplay(ptBrowse);
151
				browseAt = NO_OPERATION;
152
				show_menu(ptBrowse);
153
				switch(browseAt) {
154
					case BROWSE_FILE_SYSTEM: file = invokeFileSystemExportDialog(); break;
155
					case BROWSE_WORKSPACE: file = invokeWorkspaceExportDialog();
156
				}
157
				if(file != null) {
158
					exportCatalog(file);
159
				}
112
			}
160
			}
113
		};
161
		};
114
		exportButton.addSelectionListener(exportButtonSelectionListener);
162
		exportButton.addSelectionListener(exportButtonSelectionListener);
115
163
164
		menu = new Menu(getShell());
165
		MenuItem menuItem = new MenuItem(menu, SWT.NONE);
166
		menuItem.setText(XMLCatalogMessages.UI_BUTTON_MENU_BROWSE_WORKSPACE);
167
		browseAt = browseAt +1;
168
		browseAt = NO_OPERATION;
169
		menuItem.addSelectionListener(new SelectionAdapter() {
170
			public void widgetSelected(SelectionEvent e) {
171
				browseAt = BROWSE_WORKSPACE;
172
			}
173
		});
174
		menuItem = new MenuItem(menu, SWT.NONE);
175
		menuItem.setText(XMLCatalogMessages.UI_BUTTON_MENU_BROWSE_FILE_SYSTEM);
176
		menuItem.addSelectionListener(new SelectionAdapter() {
177
			public void widgetSelected(SelectionEvent e) {
178
				browseAt = BROWSE_FILE_SYSTEM;
179
			}
180
		});
116
		return dialogArea;
181
		return dialogArea;
117
	}
182
	}
118
183
Lines 123-130 Link Here
123
		return gd;
188
		return gd;
124
	}
189
	}
125
190
126
191
	protected String invokeFileSystemImportDialog() {
127
	protected void invokeImportDialog() {
192
		String fileName = null;
193
		FileDialog dialog = new FileDialog(getShell(), SWT.SINGLE | SWT.OPEN);
194
		String[] extensions = {"*.xmlcatalog", "*.xml","*.*"}; //$NON-NLS-1$ //$NON-NLS-2$
195
		dialog.setFilterExtensions(extensions);
196
		dialog.setText(XMLCatalogMessages.UI_LABEL_IMPORT_DIALOG_TITLE);
197
		fileName = dialog.open();
198
		return URIUtils.convertLocationToURI(fileName);
199
	}
200
	
201
	protected String invokeWorkspaceImportDialog() {
202
		String fileName = null;
128
		SelectSingleFileDialog dialog = new SelectSingleFileDialog(getShell(), null, true);
203
		SelectSingleFileDialog dialog = new SelectSingleFileDialog(getShell(), null, true);
129
		String[] extensions = {".xmlcatalog", ".xml"}; //$NON-NLS-1$ //$NON-NLS-2$
204
		String[] extensions = {".xmlcatalog", ".xml"}; //$NON-NLS-1$ //$NON-NLS-2$
130
		dialog.addFilterExtensions(extensions);
205
		dialog.addFilterExtensions(extensions);
Lines 137-162 Link Here
137
		if (rc == Window.OK) {
212
		if (rc == Window.OK) {
138
			IFile file = dialog.getFile();
213
			IFile file = dialog.getFile();
139
			if (file != null) {
214
			if (file != null) {
140
				String fileName = file.getLocation().toFile().toURI().toString();
215
				fileName = file.getLocation().toFile().toURI().toString();
141
				try {
142
					CatalogSet tempResourceSet = new CatalogSet();
143
					ICatalog newCatalog = tempResourceSet.lookupOrCreateCatalog("temp", fileName); //$NON-NLS-1$
144
					workingUserCatalog.addEntriesFromCatalog(newCatalog);
145
				}
146
				catch (Exception e) {
147
					// TODO... give error message
148
				}
149
			}
216
			}
150
			close();
151
		}
217
		}
218
		return fileName;
152
	}
219
	}
153
220
221
	protected void importCatalog(String fileName) {
222
		try {
223
			CatalogSet tempResourceSet = new CatalogSet();
224
			ICatalog newCatalog = tempResourceSet.lookupOrCreateCatalog("temp", fileName); //$NON-NLS-1$
225
			workingUserCatalog.addEntriesFromCatalog(newCatalog);
226
		}
227
		catch (Exception e) {
228
			// TODO... give error message
229
		}
230
		close();
231
	}
154
232
155
	protected void invokeExportDialog() {
233
	protected String invokeFileSystemExportDialog() {
234
		String fileName = null;
235
		FileDialog dialog = new FileDialog(getShell(), SWT.SINGLE | SWT.SAVE);
236
		String[] extensions = {"*.xmlcatalog", "*.xml","*.*"}; //$NON-NLS-1$ //$NON-NLS-2$
237
		dialog.setFilterExtensions(extensions);
238
		dialog.setText(XMLCatalogMessages.UI_LABEL_EXPORT_DIALOG_TITLE);
239
		fileName = dialog.open();
240
		File file = new File(fileName);
241
		if (file != null && file.exists() && !MessageDialog.openConfirm(getShell(), XMLCatalogMessages.UI_OVERWRITE_FILE_DIALOG_TITLE, XMLCatalogMessages.UI_OVERWRITE_FILE_DIALOG_TEXT)) {
242
			return null;
243
		}
244
		return URIUtils.convertLocationToURI(fileName);
245
	}
246
	
247
	protected String invokeWorkspaceExportDialog() {
248
		String fileName = null;
156
		IPath originalFilePath = null;
249
		IPath originalFilePath = null;
157
		IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
250
		IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
158
		if (projects.length > 0) {
251
		if (projects.length > 0) {
159
			originalFilePath = projects[0].getFullPath().append(".xmlcatalog"); //$NON-NLS-1$
252
			originalFilePath = projects[0].getFullPath().append("catalog.xmlcatalog"); //$NON-NLS-1$
160
		}
253
		}
161
254
162
		SaveAsDialog dialog = new SaveAsDialog(getShell());
255
		SaveAsDialog dialog = new SaveAsDialog(getShell());
Lines 176-204 Link Here
176
			IPath path = dialog.getResult();
269
			IPath path = dialog.getResult();
177
			if (path != null) {
270
			if (path != null) {
178
				IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
271
				IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
179
				String fileName = file.getLocation().toFile().toURI().toString();
272
				fileName = file.getLocation().toFile().toURI().toString();
180
273
				createFileIfRequired(file);
181
				// here we save the catalog entries to the selected file
182
				try {
183
					createFileIfRequired(file);
184
					workingUserCatalog.setLocation(fileName);
185
					workingUserCatalog.save();
186
				}
187
				catch (Exception ex) {
188
					try {
189
						String title = XMLCatalogMessages.UI_LABEL_CATALOG_SAVE_ERROR;
190
						String briefMessage = XMLCatalogMessages.UI_LABEL_CATALOG_COULD_NOT_BE_SAVED;
191
						String reason = file.isReadOnly() ? NLS.bind(XMLCatalogMessages.UI_LABEL_FILE_IS_READ_ONLY, fileName) : NLS.bind(XMLCatalogMessages.ERROR_SAVING_FILE, fileName);
192
						String details = NLS.bind(XMLCatalogMessages.ERROR_SAVING_FILE, fileName);
193
194
						ErrorDialog.openError(Display.getCurrent().getActiveShell(), title, briefMessage, createStatus(reason, details));
195
					}
196
					catch (Exception ex2) {
197
					}
198
				}
199
				close();
200
			}
274
			}
201
		}
275
		}
276
		return URIUtils.convertURIToLocation(fileName);
277
	}
278
279
	protected void exportCatalog(String fileName) {
280
		workingUserCatalog.setLocation(fileName);
281
		try {
282
			workingUserCatalog.save();
283
		} catch (Exception e) {
284
			try {
285
				
286
			File file = new File(fileName);
287
			fileName = file.getName();
288
			String title = XMLCatalogMessages.UI_LABEL_CATALOG_SAVE_ERROR;
289
			String briefMessage = XMLCatalogMessages.UI_LABEL_CATALOG_COULD_NOT_BE_SAVED;
290
			String reason = !file.canWrite() ? NLS.bind(XMLCatalogMessages.UI_LABEL_FILE_IS_READ_ONLY, fileName) : NLS.bind(XMLCatalogMessages.ERROR_SAVING_FILE, fileName);
291
			String details = NLS.bind(XMLCatalogMessages.ERROR_SAVING_FILE, fileName);
292
			ErrorDialog.openError(Display.getCurrent().getActiveShell(), title, briefMessage, createStatus(reason, details));
293
			}
294
			catch (Exception ex2) {
295
			}
296
		}	
297
		close();
202
	}
298
	}
203
299
204
	// TODO... This was copied from WindowUtility. Is there an easier way to
300
	// TODO... This was copied from WindowUtility. Is there an easier way to
Lines 226-229 Link Here
226
		catch (Exception e) {
322
		catch (Exception e) {
227
		}
323
		}
228
	}
324
	}
325
	
326
	private void show_menu(Point location) {
327
		menu.setLocation(location);
328
		menu.setVisible(true);
329
		while (!menu.isDisposed() && menu.isVisible()) {
330
	          if (!menu.getDisplay().readAndDispatch())
331
	            menu.getDisplay().sleep();
332
	        }
333
	}
334
	
229
}
335
}

Return to bug 113249