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(); }
/* * 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(); }