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 111879 | Differences between
and this patch

Collapse All | Expand All

(-)src-catalog/org/eclipse/wst/xml/ui/internal/catalog/EditCatalogEntryDialog.java (-108 / +131 lines)
Lines 22-33 Link Here
22
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.events.ModifyEvent;
23
import org.eclipse.swt.events.ModifyEvent;
24
import org.eclipse.swt.events.ModifyListener;
24
import org.eclipse.swt.events.ModifyListener;
25
import org.eclipse.swt.events.SelectionAdapter;
26
import org.eclipse.swt.events.SelectionEvent;
25
import org.eclipse.swt.events.SelectionEvent;
27
import org.eclipse.swt.events.SelectionListener;
26
import org.eclipse.swt.events.SelectionListener;
28
import org.eclipse.swt.graphics.Color;
27
import org.eclipse.swt.graphics.Color;
29
import org.eclipse.swt.graphics.Image;
28
import org.eclipse.swt.graphics.Image;
30
import org.eclipse.swt.graphics.Point;
31
import org.eclipse.swt.graphics.Rectangle;
29
import org.eclipse.swt.graphics.Rectangle;
32
import org.eclipse.swt.layout.FormAttachment;
30
import org.eclipse.swt.layout.FormAttachment;
33
import org.eclipse.swt.layout.FormData;
31
import org.eclipse.swt.layout.FormData;
Lines 40-47 Link Here
40
import org.eclipse.swt.widgets.Control;
38
import org.eclipse.swt.widgets.Control;
41
import org.eclipse.swt.widgets.FileDialog;
39
import org.eclipse.swt.widgets.FileDialog;
42
import org.eclipse.swt.widgets.Label;
40
import org.eclipse.swt.widgets.Label;
43
import org.eclipse.swt.widgets.Menu;
44
import org.eclipse.swt.widgets.MenuItem;
45
import org.eclipse.swt.widgets.Shell;
41
import org.eclipse.swt.widgets.Shell;
46
import org.eclipse.swt.widgets.Text;
42
import org.eclipse.swt.widgets.Text;
47
import org.eclipse.swt.widgets.ToolBar;
43
import org.eclipse.swt.widgets.ToolBar;
Lines 64-70 Link Here
64
60
65
	protected class CatalogEntryPage extends CatalogElementPage {
61
	protected class CatalogEntryPage extends CatalogElementPage {
66
62
67
		protected Button browseButton;
63
		protected Button browseWorkspaceButton;
64
		
65
		protected Button browseFileSystemButton;
68
66
69
		protected ICatalogEntry catalogEntry;
67
		protected ICatalogEntry catalogEntry;
70
68
Lines 168-174 Link Here
168
			gd = new GridData(GridData.FILL_HORIZONTAL);
166
			gd = new GridData(GridData.FILL_HORIZONTAL);
169
			group.setLayoutData(gd);
167
			group.setLayoutData(gd);
170
168
171
			layout = new GridLayout(3, false);
169
			layout = new GridLayout(2, false);
172
			group.setLayout(layout);
170
			group.setLayout(layout);
173
171
174
			Label resourceLocationLabel = new Label(group, SWT.NONE);
172
			Label resourceLocationLabel = new Label(group, SWT.NONE);
Lines 186-199 Link Here
186
			// XMLBuilderContextIds.XMLP_ENTRY_URI);
184
			// XMLBuilderContextIds.XMLP_ENTRY_URI);
187
			resourceLocationField.addModifyListener(modifyListener);
185
			resourceLocationField.addModifyListener(modifyListener);
188
186
189
190
			browseButton = createBrowseButton(group);
191
			// WorkbenchHelp.setHelp(browseButton,
187
			// WorkbenchHelp.setHelp(browseButton,
192
			// XMLBuilderContextIds.XMLP_ENTRY_BROWSE);
188
			// XMLBuilderContextIds.XMLP_ENTRY_BROWSE);
193
			browseButton.addSelectionListener(new DropDownSelectionListener(resourceLocationField));
194
189
190
			Composite browseButtonsComposite = new Composite(group, SWT.FLAT);
191
			gd = new GridData(GridData.FILL_HORIZONTAL);
192
			gd.horizontalSpan = 2;
193
			gd.horizontalAlignment = GridData.END;
194
			browseButtonsComposite.setLayoutData(gd);
195
			
196
			layout = new GridLayout();
197
			layout.numColumns = 2;
198
			layout.marginWidth = 0;
199
			layout.marginHeight = 0;
200
			layout.marginBottom = 5;
201
			browseButtonsComposite.setLayout(layout);
202
			
203
			browseWorkspaceButton = new Button(browseButtonsComposite, SWT.FLAT);
204
			browseWorkspaceButton.setText(XMLCatalogMessages.UI_BUTTON_MENU_BROWSE_WORKSPACE);
205
			browseWorkspaceButton.addSelectionListener(new SelectionListener(){
206
207
				public void widgetDefaultSelected(SelectionEvent e) {
208
				}
209
210
				public void widgetSelected(SelectionEvent e) {
211
					String value = invokeWorkspaceFileSelectionDialog();
212
					if(value != null) {
213
						resourceLocationField.setText(value);
214
					}
215
				}
216
			});
217
			
218
			browseFileSystemButton = new Button(browseButtonsComposite, SWT.FLAT);
219
			browseFileSystemButton.setText(XMLCatalogMessages.UI_BUTTON_MENU_BROWSE_FILE_SYSTEM);
220
			browseFileSystemButton.addSelectionListener(new SelectionListener(){
221
222
				public void widgetDefaultSelected(SelectionEvent e) {
223
				}
224
225
				public void widgetSelected(SelectionEvent e) {
226
					String value = invokeFileSelectionDialog();
227
					if(value != null) {
228
						resourceLocationField.setText(value);
229
					}
230
				}
231
			});
232
			
195
			// Key Type
233
			// Key Type
196
			//
234
			//
235
			
197
			Label keyTypeLabel = new Label(group, SWT.NONE);
236
			Label keyTypeLabel = new Label(group, SWT.NONE);
198
			keyTypeLabel.setText(XMLCatalogMessages.UI_KEY_TYPE_COLON);
237
			keyTypeLabel.setText(XMLCatalogMessages.UI_KEY_TYPE_COLON);
199
238
Lines 207-216 Link Here
207
			// WorkbenchHelp.setHelp(keyTypeCombo,
246
			// WorkbenchHelp.setHelp(keyTypeCombo,
208
			// XMLBuilderContextIds.XMLP_ENTRY_KEY_TYPE);
247
			// XMLBuilderContextIds.XMLP_ENTRY_KEY_TYPE);
209
248
210
			// a placeholder to fill the 3rd column
211
			Button placeHolder = new Button(group, SWT.NONE);
212
			placeHolder.setVisible(false);
213
214
			// Key
249
			// Key
215
			// 
250
			// 
216
			Label keyValueLabel = new Label(group, SWT.NONE);
251
			Label keyValueLabel = new Label(group, SWT.NONE);
Lines 564-571 Link Here
564
	}
599
	}
565
600
566
	protected class NextCatalogPage extends CatalogElementPage {
601
	protected class NextCatalogPage extends CatalogElementPage {
567
		protected Button browseButton;
602
		
568
603
		protected Button browseWorkspaceButton;
604
		
605
		protected Button browseFileSystemButton;
606
		
569
		protected Text catalogLocationField;
607
		protected Text catalogLocationField;
570
608
571
		protected INextCatalog nextCatalog;
609
		protected INextCatalog nextCatalog;
Lines 623-646 Link Here
623
			gd = new GridData(GridData.FILL_HORIZONTAL);
661
			gd = new GridData(GridData.FILL_HORIZONTAL);
624
			group.setLayoutData(gd);
662
			group.setLayoutData(gd);
625
663
626
			layout = new GridLayout(2, false);
664
			layout = new GridLayout();
627
			group.setLayout(layout);
665
			group.setLayout(layout);
628
666
629
			Label resourceLocationLabel = new Label(group, SWT.NONE);
667
			Label resourceLocationLabel = new Label(group, SWT.NONE);
630
			resourceLocationLabel.setText(XMLCatalogMessages.UI_LABEL_CATALOG_URI_COLON);
668
			resourceLocationLabel.setText(XMLCatalogMessages.UI_LABEL_CATALOG_URI_COLON);
631
669
632
			// filler
633
			new Label(group, SWT.NONE);
634
635
			catalogLocationField = new Text(group, SWT.SINGLE | SWT.BORDER);
670
			catalogLocationField = new Text(group, SWT.SINGLE | SWT.BORDER);
636
			catalogLocationField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
671
			catalogLocationField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
637
			catalogLocationField.setText(URIUtils.convertURIToLocation(getDisplayValue(getNextCatalog().getCatalogLocation())));
672
			catalogLocationField.setText(URIUtils.convertURIToLocation(getDisplayValue(getNextCatalog().getCatalogLocation())));
638
			// WorkbenchHelp.setHelp(resourceLocationField,
673
			// WorkbenchHelp.setHelp(resourceLocationField,
639
			// XMLBuilderContextIds.XMLP_ENTRY_URI);
674
			// XMLBuilderContextIds.XMLP_ENTRY_URI);
640
			catalogLocationField.addModifyListener(modifyListener);
675
			catalogLocationField.addModifyListener(modifyListener);
676
			
677
			Composite browseButtonsComposite = new Composite(group, SWT.FLAT);
678
			gd = new GridData(GridData.FILL_HORIZONTAL);
679
			gd.horizontalSpan = 2;
680
			gd.horizontalAlignment = GridData.END;
681
			browseButtonsComposite.setLayoutData(gd);
682
			
683
			layout = new GridLayout();
684
			layout.numColumns = 2;
685
			layout.marginWidth = 0;
686
			layout.marginHeight = 0;
687
			layout.marginBottom = 5;
688
			browseButtonsComposite.setLayout(layout);
689
			
690
			browseWorkspaceButton = new Button(browseButtonsComposite, SWT.FLAT);
691
			browseWorkspaceButton.setText(XMLCatalogMessages.UI_BUTTON_MENU_BROWSE_WORKSPACE);
692
			browseWorkspaceButton.addSelectionListener(new SelectionListener(){
641
693
642
			browseButton = createBrowseButton(group);
694
				public void widgetDefaultSelected(SelectionEvent e) {
643
			browseButton.addSelectionListener(new DropDownSelectionListener(catalogLocationField));
695
				}
696
697
				public void widgetSelected(SelectionEvent e) {
698
					String value = invokeWorkspaceFileSelectionDialog();
699
					if(value != null) {
700
						catalogLocationField.setText(value);
701
					}
702
				}
703
			});
704
			
705
			browseFileSystemButton = new Button(browseButtonsComposite, SWT.FLAT);
706
			browseFileSystemButton.setText(XMLCatalogMessages.UI_BUTTON_MENU_BROWSE_FILE_SYSTEM);
707
			browseFileSystemButton.addSelectionListener(new SelectionListener(){
708
709
				public void widgetDefaultSelected(SelectionEvent e) {
710
				}
711
712
				public void widgetSelected(SelectionEvent e) {
713
					String value = invokeFileSelectionDialog();
714
					if(value != null) {
715
						catalogLocationField.setText(value);
716
					}
717
				}
718
			});
644
719
645
			errorMessageLabel = new Label(group, SWT.NONE);
720
			errorMessageLabel = new Label(group, SWT.NONE);
646
			errorMessageLabel.setForeground(color);
721
			errorMessageLabel.setForeground(color);
Lines 958-1053 Link Here
958
		return browseButton;
1033
		return browseButton;
959
1034
960
	}
1035
	}
961
1036
	
962
	class DropDownSelectionListener extends SelectionAdapter {
1037
	protected Button createWorkspaceBrowseButton(Composite composite) {
963
		private Menu menu = null;
1038
		Button browseWorkspaceButton = new Button(composite, SWT.FLAT);
964
		private Control control;
1039
		browseWorkspaceButton.setText(XMLCatalogMessages.UI_BUTTON_MENU_BROWSE_WORKSPACE);
965
1040
		//GridData gd = new GridData();
966
		public DropDownSelectionListener(Control aControl) {
1041
		//browseButton.setLayoutData(gd);
967
			super();
1042
		return browseWorkspaceButton;
968
			this.control = aControl;
1043
	}
969
		}
1044
	
970
1045
	protected Button createFileSystemBrowseButton(Composite composite) {
971
		public void widgetSelected(SelectionEvent event) {
1046
		Button browseFileSystemButton = new Button(composite, SWT.FLAT);
972
			// Create the menu if it has not already been created
1047
		browseFileSystemButton.setText(XMLCatalogMessages.UI_BUTTON_MENU_BROWSE_WORKSPACE);
973
			if (menu == null) {
1048
		//GridData gd = new GridData();
974
				// Lazy create the menu.
1049
		//browseButton.setLayoutData(gd);
975
				menu = new Menu(getShell());
1050
		return browseFileSystemButton;
976
				MenuItem menuItem = new MenuItem(menu, SWT.NONE);
1051
	}
977
				menuItem.setText(XMLCatalogMessages.UI_BUTTON_MENU_BROWSE_WORKSPACE);
1052
978
				/*
1053
	
979
				 * Add a menu selection listener so that the menu is hidden
1054
	String invokeWorkspaceFileSelectionDialog() {
980
				 * when the user selects an item from the drop down menu.
1055
		FilterableSelectSingleFileDialog dialog = new FilterableSelectSingleFileDialog(getShell());
981
				 */
1056
		dialog.createAndOpen();
982
				menuItem.addSelectionListener(new SelectionAdapter() {
1057
		IFile file = dialog.getFile();
983
					public void widgetSelected(SelectionEvent e) {
1058
		String uri = null;
984
						setMenuVisible(false);
1059
		if (file != null) {
985
						invokeWorkspaceFileSelectionDialog();
1060
			// remove leading slash from the value to avoid the
986
					}
1061
			// whole leading slash ambiguity problem
987
				});
1062
			//                    
988
1063
			uri = file.getFullPath().toString();
989
				menuItem = new MenuItem(menu, SWT.NONE);
1064
			while (uri.startsWith("/") || uri.startsWith("\\")) { //$NON-NLS-1$ //$NON-NLS-2$
990
				menuItem.setText(XMLCatalogMessages.UI_BUTTON_MENU_BROWSE_FILE_SYSTEM);
1065
				uri = uri.substring(1);
991
				/*
992
				 * Add a menu selection listener so that the menu is hidden
993
				 * when the user selects an item from the drop down menu.
994
				 */
995
				menuItem.addSelectionListener(new SelectionAdapter() {
996
					public void widgetSelected(SelectionEvent e) {
997
						setMenuVisible(false);
998
						invokeFileSelectionDialog();
999
					}
1000
				});
1001
1002
			}
1003
1004
			// Position the menu below and vertically aligned with the the
1005
			// drop down tool button.
1006
			Button button = (Button) event.widget;
1007
1008
			// set location
1009
			Point ptBrowse = button.getLocation();
1010
			Rectangle rcBrowse = button.getBounds();
1011
			ptBrowse.y += rcBrowse.height;
1012
			ptBrowse = button.getParent().toDisplay(ptBrowse);
1013
			menu.setLocation(ptBrowse.x, ptBrowse.y);
1014
1015
			setMenuVisible(true);
1016
1017
		}
1018
1019
		void setMenuVisible(boolean visible) {
1020
			menu.setVisible(visible);
1021
			// this.visible = visible;
1022
		}
1023
1024
		void invokeWorkspaceFileSelectionDialog() {
1025
			FilterableSelectSingleFileDialog dialog = new FilterableSelectSingleFileDialog(getShell());
1026
			dialog.createAndOpen();
1027
1028
			IFile file = dialog.getFile();
1029
			if (file != null) {
1030
				// remove leading slash from the value to avoid the
1031
				// whole leading slash ambiguity problem
1032
				//                    
1033
				String uri = file.getFullPath().toString();
1034
				while (uri.startsWith("/") || uri.startsWith("\\")) { //$NON-NLS-1$ //$NON-NLS-2$
1035
					uri = uri.substring(1);
1036
				}
1037
				if (control instanceof Text) {
1038
					((Text) control).setText(uri);
1039
				}
1040
1041
			}
1066
			}
1042
		}
1067
		}
1068
		return uri;
1069
	}
1043
1070
1044
		void invokeFileSelectionDialog() {
1071
	String invokeFileSelectionDialog() {
1045
			FileDialog dialog = new FileDialog(getShell(), SWT.SINGLE);
1072
		FileDialog dialog = new FileDialog(getShell(), SWT.SINGLE);
1046
			String file = dialog.open();
1073
		return dialog.open();
1047
			if ((control instanceof Text) && (file != null)) {
1048
				((Text) control).setText(file);
1049
			}
1050
		}
1051
	}
1074
	}
1052
1075
1053
}
1076
}

Return to bug 111879