private void createFileSelectionArea(Composite workArea) { Composite composite = new Composite(workArea, SWT.NULL); composite.setLayout(new GridLayout()); composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); GridLayout layout = new GridLayout(); layout.numColumns = 3; layout.marginHeight = 0; layout.marginWidth = 0; composite.setLayout(layout); Label label = new Label(composite, SWT.NONE); label.setText(Messages.ServiceConfigurationImportWizard_2); fileCombo = new Combo(composite, SWT.DROP_DOWN); GridData comboData = new GridData(GridData.FILL_HORIZONTAL); comboData.verticalAlignment = GridData.CENTER; comboData.grabExcessVerticalSpace = false; comboData.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH; fileCombo.setLayoutData(comboData); file = FilenameStore.getSuggestedDefault(); fileCombo.setItems(FilenameStore.getHistory()); fileCombo.setText(file); fileCombo.addListener( SWT.Modify, new Listener() { public void handleEvent(Event event) { file = fileCombo.getText(); updateEnablement(); } }); browseButton = new Button(composite, SWT.PUSH); browseButton.setText(Messages.ServiceConfigurationImportWizard_3); GridData data = new GridData(); data.horizontalAlignment = GridData.FILL; int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); data.widthHint = Math.max(widthHint, browseButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); browseButton.setLayoutData(data); browseButton.addListener( SWT.Selection, new Listener() { public void handleEvent(Event event) { FileDialog d = new FileDialog(getShell(), SWT.OPEN); d.setFilterExtensions(new String[] {"*.cfg", "*"}); // $NON-NLS-1$ //$NON-NLS-2$ d.setFilterNames( new String[] { Messages.ServiceConfigurationImportWizard_4, Messages.ServiceConfigurationImportWizard_5 }); String fileName = getFileName(); if (fileName != null && fileName.length() > 0) { int separator = fileName.lastIndexOf( System.getProperty("file.separator").charAt(0)); // $NON-NLS-1$ if (separator != -1) { fileName = fileName.substring(0, separator); } } else { fileName = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString(); } d.setFilterPath(fileName); String f = d.open(); if (f != null) { fileCombo.setText(f); file = f; updateConfigurations(file); } } }); }
/* (non-Javadoc) * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection) */ public void init(IWorkbench workbench, IStructuredSelection selection) { FilenameStore.setDefaultFromSelection(workbench); }