/** * Get the "resourceGroup" field for the specified dialog. This is a silly * hack to workaround org.eclipse.ui.dialogs.SaveAsDialog's resourceGroup * field and class not being public or protected, or otherwise supporting * methods to manipulate the UI programatically. */ protected static synchronized ResourceAndContainerGroup getResourceGroup(final SaveAsDialog2 d) { boolean origAccessible = false; try { // cache it to avoid unneccessary reflection look ups if (resourceGroupField == null) { resourceGroupField = org.eclipse.ui.dialogs.SaveAsDialog.class.getDeclaredField("resourceGroup"); //$NON-NLS-1$ } // make it accessible, since it's normally private origAccessible = resourceGroupField.isAccessible(); try { resourceGroupField.setAccessible(true); return (ResourceAndContainerGroup) resourceGroupField.get(d); } finally { resourceGroupField.setAccessible(origAccessible); } } catch (final Exception ex) { return null; } }
@Override protected Control createDialogArea(Composite parent) { final Composite topLevel = new Composite(parent, SWT.NONE); topLevel.setLayout(new GridLayout()); topLevel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL)); topLevel.setFont(parent.getFont()); resourceGroup = new ResourceAndContainerGroup(topLevel, this, "File name:", IDEWorkbenchMessages.WizardNewFileCreationPage_file, false, 250); resourceGroup.setResourceExtension(fileExtension); resourceGroup.setContainerFullPath(new Path(initialFolder).removeLastSegments(1)); if (new Path(initialFolder).lastSegment() != null) { resourceGroup.setResource(new Path(initialFolder).lastSegment()); resourceGroup.setFocus(); } setTitle("File"); return super.createDialogArea(parent); }
/** * (non-Javadoc) Method declared on IDialogPage. */ public void createControl(Composite parent) { initializeDialogUnits(parent); // top level group Composite topLevel = new Composite(parent, SWT.NONE); topLevel.setLayout(new GridLayout()); topLevel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL)); topLevel.setFont(parent.getFont()); PlatformUI.getWorkbench().getHelpSystem() .setHelp(topLevel, IIDEHelpContextIds.NEW_FILE_WIZARD_PAGE); // resource and container group resourceGroup = new ResourceAndContainerGroup(topLevel, this, getNewFileLabel(), IDEWorkbenchMessages.WizardNewFileCreationPage_file, false, SIZING_CONTAINER_GROUP_HEIGHT); resourceGroup.setAllowExistingResources(initialAllowExistingResources); initialPopulateContainerNameField(); createAdvancedControls(topLevel); if (initialFileName != null) { resourceGroup.setResource(initialFileName); } if (initialFileExtension != null) { resourceGroup.setResourceExtension(initialFileExtension); } validatePage(); // Show description on opening setErrorMessage(null); setMessage(null); setControl(topLevel); }
/** * Returns the current file name as entered by the user, or its anticipated * initial value. * * @return the file name, its anticipated initial value, or * <code>null</code> if no file name is known */ public String getFileName() { final ResourceAndContainerGroup resourceGroup = getResourceGroup(this); if (resourceGroup != null) { return resourceGroup.getResource(); } return ""; //$NON-NLS-1$ }
/** * Set the filename of the dialog. */ public void setFileName(final String filename) { final ResourceAndContainerGroup resourceGroup = getResourceGroup(this); if (resourceGroup != null) { resourceGroup.setResource(filename); } else { setOriginalName(filename); } }
@Override protected Control createDialogArea(Composite parent) { final Composite topLevel = new Composite(parent, SWT.NONE); topLevel.setLayout(new GridLayout()); topLevel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL)); topLevel.setFont(parent.getFont()); resourceGroup = new ResourceAndContainerGroup(topLevel, this, "Directory name:", "folder", false, 250); resourceGroup.setContainerFullPath(new Path(initialFolder)); setTitle("Directory"); return super.createDialogArea(parent); }
/** * Returns whether this page's controls currently all contain valid values. * * @return <code>true</code> if all controls are valid, and * <code>false</code> if at least one is invalid */ protected boolean validatePage() { boolean valid = true; if (!resourceGroup.areAllValuesValid()) { // if blank name then fail silently if (resourceGroup.getProblemType() == ResourceAndContainerGroup.PROBLEM_RESOURCE_EMPTY || resourceGroup.getProblemType() == ResourceAndContainerGroup.PROBLEM_CONTAINER_EMPTY) { setMessage(resourceGroup.getProblemMessage()); setErrorMessage(null); } else { setErrorMessage(resourceGroup.getProblemMessage()); } valid = false; } String resourceName = resourceGroup.getResource(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IStatus result = workspace.validateName(resourceName, IResource.FILE); if (!result.isOK()) { setErrorMessage(result.getMessage()); return false; } IStatus linkedResourceStatus = null; if (valid) { linkedResourceStatus = validateLinkedResource(); if (linkedResourceStatus.getSeverity() == IStatus.ERROR) { valid = false; } } // validateLinkedResource sets messages itself if (valid && (linkedResourceStatus == null || linkedResourceStatus.isOK())) { setMessage(null); setErrorMessage(null); // perform "resource exists" check if it was skipped in // ResourceAndContainerGroup if (resourceGroup.getAllowExistingResources()) { String problemMessage = NLS.bind( IDEWorkbenchMessages.ResourceGroup_nameExists, getFileName()); IPath resourcePath = getContainerFullPath().append( getFileName()); if (workspace.getRoot().getFolder(resourcePath).exists()) { setErrorMessage(problemMessage); valid = false; } if (workspace.getRoot().getFile(resourcePath).exists()) { setMessage(problemMessage, IMessageProvider.WARNING); } } } if (isFilteredByParent()) { setMessage( IDEWorkbenchMessages.WizardNewFileCreationPage_resourceWillBeFilteredWarning, IMessageProvider.ERROR); setupLinkedResourceTarget(); valid = false; } return valid; }