protected void updateURLComponents(String urlStr) { try { URL url = new URL(urlStr); String port = url.getPort() == -1 ? "" : ":" + url.getPort(); // $NON-NLS-1$ //$NON-NLS-2$ fURLHost.setText( url.getProtocol() + "://" + url.getHost() + port + "/"); // $NON-NLS-1$ //$NON-NLS-2$ if (url.getQuery() != null) { fURLPath.setText(url.getPath() + "?" + url.getQuery()); // $NON-NLS-1$ } else { fURLPath.setText(url.getPath()); } } catch (MalformedURLException e) { Logger.logException(e); } }
/** Tests if the current workbench selection is a suitable container to use. */ private void initialize() { if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) { IStructuredSelection ssel = (IStructuredSelection) selection; if (ssel.size() > 1) { return; } Object obj = ssel.getFirstElement(); if (obj instanceof IResource) { IContainer container; if (obj instanceof IContainer) { container = (IContainer) obj; } else { container = ((IResource) obj).getParent(); } containerText.setText(container.getFullPath().toString()); } } fileText.setText("new.gaml"); }
/** * Uses the standard container selection dialog to choose the new value for the container field. */ private void handleBrowse() { ContainerSelectionDialog dialog = new ContainerSelectionDialog( getShell(), ResourcesPlugin.getWorkspace().getRoot(), false, "Select a project as a container"); if (dialog.open() == Window.OK) { Object[] result = dialog.getResult(); if (result.length == 1) { containerText.setText(((Path) result[0]).toString()); } } }
protected void handleFileButtonSelected() { IResource file = null; file = getFileFromDialog(null); if (file == null) return; String fName = file.getFullPath().toString(); fFile.setText(fName); if (autoGeneratedURL.getSelection()) { updateURLComponents(computeURL(formatFileName(fName))); } }
private void radioChanged() { if (exampleModelButton.getSelection()) { descriptionText.setText("This model displays an awesome simulation of something ..."); titleText.setText("example"); fileText.setText("example.gaml"); updateStatus(null); } if (emptyModelButton.getSelection() || skeletonModelButton.getSelection()) { descriptionText.setText(""); titleText.setText("new"); fileText.setText("new.gaml"); updateStatus(null); } dialogChanged(); }
/** @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(ILaunchConfiguration) */ public void initializeFrom(ILaunchConfiguration configuration) { serverCombo.setEnabled(true); // remove error message that other instances may have set setErrorMessage(null); try { String fileName = configuration.getAttribute(Server.FILE_NAME, ""); // $NON-NLS-1$ String url = configuration.getAttribute(Server.BASE_URL, ""); // $NON-NLS-1$ boolean isAutoGeneratedURL = configuration.getAttribute(AUTO_GENERATED_URL, true); initializeServerControl(configuration); if (isAutoGeneratedURL) { autoGeneratedURL.setSelection(true); String computedURL = computeURL(formatFileName(fileName)); fURLLabel.setEnabled(false); updateURLComponents(computedURL); fURLPath.setEnabled(false); } else { autoGeneratedURL.setSelection(false); fURLLabel.setEnabled(true); updateURLComponents(url); fURLPath.setEnabled(true); } fFile.setText(fileName); updateFileEnabled(configuration); updateURLEnabled(configuration); } catch (CoreException e) { // ignore } initializeExtensionControls(configuration); isValid(configuration); }
@Override public void createControl(final Composite parent) { Composite container = new Composite(parent, SWT.NULL); GridLayout layout = new GridLayout(); container.setLayout(layout); layout.numColumns = 3; layout.verticalSpacing = 9; Label label = new Label(container, SWT.NULL); label.setText("&Container:"); containerText = new Text(container, SWT.BORDER | SWT.SINGLE); GridData gd = new GridData(GridData.FILL_HORIZONTAL); containerText.setLayoutData(gd); containerText.addModifyListener( new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { dialogChanged(); } }); Button button = new Button(container, SWT.PUSH); button.setText("Browse..."); button.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { handleBrowse(); } }); label = new Label(container, SWT.NULL); label.setText("&Choose a model:"); Composite middleComposite = new Composite(container, SWT.NULL); FillLayout fillLayout = new FillLayout(); middleComposite.setLayout(fillLayout); emptyModelButton = new Button(middleComposite, SWT.RADIO); emptyModelButton.setText("Empty"); emptyModelButton.setSelection(true); skeletonModelButton = new Button(middleComposite, SWT.RADIO); skeletonModelButton.setText("Skeleton"); exampleModelButton = new Button(middleComposite, SWT.RADIO); exampleModelButton.setText("Example"); emptyModelButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent se) { typeOfModel = "empty"; radioChanged(); } }); exampleModelButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent se) { typeOfModel = "example"; radioChanged(); } }); skeletonModelButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent se) { typeOfModel = "skeleton"; radioChanged(); } }); /* Need to add empty label so the next controls are pushed to the next line in the grid. */ label = new Label(container, SWT.NULL); label.setText(""); label = new Label(container, SWT.NULL); label.setText("&File name:"); fileText = new Text(container, SWT.BORDER | SWT.SINGLE); gd = new GridData(GridData.FILL_HORIZONTAL); fileText.setLayoutData(gd); fileText.addModifyListener( new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { Text t = (Text) e.getSource(); String fname = t.getText(); int i = fname.lastIndexOf(".gaml"); if (i > 0) { // model title = filename less extension less all non alphanumeric characters titleText.setText(fname.substring(0, i).replaceAll("[^\\p{Alnum}]", "")); } /* * else if (fname.length()>0) { * int pos = t.getSelection().x; * fname = fname.replaceAll("[[^\\p{Alnum}]&&[^_-]&&[^\\x2E]]", "_"); * t.setText(fname+".gaml"); * t.setSelection(pos); * } else { * t.setText("new.gaml"); * } */ dialogChanged(); } }); /* Need to add empty label so the next two controls are pushed to the next line in the grid. */ label = new Label(container, SWT.NULL); label.setText(""); label = new Label(container, SWT.NULL); label.setText("&Author:"); authorText = new Text(container, SWT.BORDER | SWT.SINGLE); gd = new GridData(GridData.FILL_HORIZONTAL); authorText.setLayoutData(gd); authorText.setText(getComputerFullName()); authorText.addModifyListener( new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { dialogChanged(); } }); /* Need to add empty label so the next two controls are pushed to the next line in the grid. */ label = new Label(container, SWT.NULL); label.setText(""); label = new Label(container, SWT.NULL); label.setText("&Model name:"); titleText = new Text(container, SWT.BORDER | SWT.SINGLE); gd = new GridData(GridData.FILL_HORIZONTAL); titleText.setLayoutData(gd); titleText.setText("new"); titleText.addModifyListener( new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { dialogChanged(); } }); /* Need to add empty label so the next two controls are pushed to the next line in the grid. */ label = new Label(container, SWT.NULL); label.setText(""); label = new Label(container, SWT.NULL); label.setText("&Model description:"); descriptionText = new Text(container, SWT.WRAP | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); descriptionText.setBounds(0, 0, 250, 100); gd = new GridData(SWT.FILL, SWT.FILL, true, false); gd.verticalSpan = 4; descriptionText.setLayoutData(gd); /* * Need to add seven empty labels in order to push next controls after the descriptionText * box. */ // TODO Dirty!! Change the way to do this for (int i = 0; i < 7; i++) { label = new Label(container, SWT.NULL); label.setText(""); } label = new Label(container, SWT.NULL); label.setText("&Create a html template \nfor the model description ?"); middleComposite = new Composite(container, SWT.NULL); fillLayout = new FillLayout(); middleComposite.setLayout(fillLayout); yesButton = new Button(middleComposite, SWT.RADIO); yesButton.setText("Yes"); yesButton.setSelection(true); Button noButton = new Button(middleComposite, SWT.RADIO); noButton.setText("No"); yesButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent se) { dialogChanged(); } }); /* Finished adding the custom control */ initialize(); dialogChanged(); setControl(container); }