protected void initializeServerControl(ILaunchConfiguration configuration) { try { String serverName = configuration.getAttribute(Server.NAME, ""); // $NON-NLS-1$ if (serverName != null && !serverName.equals("")) { // $NON-NLS-1$ server = ServersManager.getServer(serverName); if (server == null) { // server no longer exists setErrorMessage( PHPServerUIMessages.getString("ServerTab.invalidServerError")); // $NON-NLS-1$ selectDefaultServer(configuration); } else { serverCombo.setText(server.getName()); } } else { selectDefaultServer(configuration); } // flag should only be set if launch has been attempted on the // config if (configuration.getAttribute(READ_ONLY, false)) { serverCombo.setEnabled(false); } boolean enabled = configuration.getAttribute(SERVER_ENABLED, true); serverCombo.setEnabled(enabled); createNewServer.setEnabled(enabled); } catch (Exception e) { } }
/* * Select the default server. */ private void selectDefaultServer(ILaunchConfiguration configuration) throws CoreException { if (serverCombo != null && serverCombo.getItemCount() > 0) { // Select the default server String projectName = configuration.getAttribute(IPHPDebugConstants.PHP_Project, (String) null); IProject project = null; if (projectName != null) { project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); } Server defaultServer = ServersManager.getDefaultServer(project); int nameIndex = serverCombo.indexOf(defaultServer.getName()); if (nameIndex > -1) { serverCombo.select(nameIndex); } else { serverCombo.select(0); } server = ServersManager.getServer(serverCombo.getText()); } }
/** Called when a server is selected. This method should not be called directly. */ protected void handleServerSelection() { int numEntries = serverCombo.getItemCount(); int index = serverCombo.getSelectionIndex(); if (!servers.isEmpty()) { Object obj = servers.get(serverCombo.getSelectionIndex()); if (obj != null && obj instanceof Server) { server = servers.get(serverCombo.getSelectionIndex()); initializeURLControl(); } } if (server == null && (index + 1) != numEntries) setErrorMessage( PHPServerUIMessages.getString("ServerTab.noSelectedServerError")); // $NON-NLS-1$ else { setErrorMessage(null); } updateLaunchConfigurationDialog(); }
protected void handleConfigureButtonSelected() { int selectionIndex = serverCombo.getSelectionIndex(); Server server = servers.get(selectionIndex); String serverName = server.getName(); Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); NullProgressMonitor monitor = new NullProgressMonitor(); ServerEditDialog dialog = new ServerEditDialog(shell, server); if (dialog.open() == Window.CANCEL) { monitor.setCanceled(true); return; } ServersManager.save(); String newName = server.getName(); if (!newName.equals(serverName)) { serverCombo.remove(selectionIndex); serverCombo.add(newName, selectionIndex); serverCombo.select(selectionIndex); } saveWorkingCopy = true; handleServerSelection(); }
protected void createServerSelectionControl(Composite parent) { Group group = new Group(parent, SWT.NONE); group.setText(PHPServerUIMessages.getString("ServerTab.server")); // $NON-NLS-1$ GridLayout ly = new GridLayout(1, false); ly.marginHeight = 0; ly.marginWidth = 0; group.setLayout(ly); group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Composite phpServerComp = new Composite(group, SWT.NONE); phpServerComp.setLayout(new GridLayout(4, false)); phpServerComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); phpServerComp.setFont(parent.getFont()); Label label = new Label(phpServerComp, SWT.WRAP); GridData data = new GridData(GridData.BEGINNING); data.widthHint = 100; label.setLayoutData(data); label.setFont(parent.getFont()); label.setText(PHPServerUIMessages.getString("ServerLaunchConfigurationTab.0")); // $NON-NLS-1$ serverCombo = new Combo(phpServerComp, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY); serverCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); serverCombo.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { handleServerSelection(); } }); createNewServer = createPushButton( phpServerComp, PHPServerUIMessages.getString("ServerTab.new"), null); // $NON-NLS-1$ createNewServer.addSelectionListener(fListener); configureServers = createPushButton( phpServerComp, PHPServerUIMessages.getString("ServerTab.configure"), null); //$NON-NLS-1$ configureServers.addSelectionListener(fListener); servers = new ArrayList<Server>(); populateServerList(servers); // initialize the servers list if (!servers.isEmpty()) { for (int i = 0; i < servers.size(); i++) { Server svr = servers.get(i); serverCombo.add(svr.getName()); } } // select first item in list if (serverCombo.getItemCount() > 0) { serverCombo.select(0); } serverCombo.forceFocus(); }
/** @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); }