protected void doStatusUpdate() { if (projectCombo != null) { projectStatus = projectText.trim().equals("") ? Util.getErrorStatus("Project cannot be empty") : Util.okStatus; // $NON-NLS-2$ } if (moduleCombo != null) { moduleStatus = moduleText.trim().equals("") ? Util.getErrorStatus("Module cannot be empty") : Util.okStatus; // $NON-NLS-2$ } if (serviceUriText != null) { serviceUriStatus = serviceUri.trim().equals("") ? Util.getErrorStatus("Service URI cannot be empty") : Util.okStatus; // $NON-NLS-2$ } IStatus[] status = new IStatus[] { projectStatus, moduleStatus, fTypeNameStatus, fSuperInterfacesStatus, serviceUriStatus }; updateStatus(status); }
public void addPages() { if (!Util.isGwtHomeSet()) addPage(new GwtHomeConfirmationPage()); wizardPage = new NewGwtModuleWizardPage(); wizardPage.init(selection); addPage(wizardPage); }
/** * @param monitor * @throws Exception */ private void addServletToGwtXml(IProgressMonitor monitor) throws Exception { monitor = Util.getNonNullMonitor(monitor); try { monitor.beginTask("", 1); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); File moduleFile = getModuleFile(); Document document = builder.parse(moduleFile); Node module = document.getDocumentElement(); Element newServlet = document.createElement("servlet"); newServlet.setAttribute("path", "/" + serviceUri); // $NON-NLS-2$ newServlet.setAttribute( "class", getPackageFragment().getElementName() + '.' + getTypeName() + "Impl"); // $NON-NLS-2$ module.appendChild(newServlet); Transformer writer = TransformerFactory.newInstance().newTransformer(); writer.transform(new DOMSource(document), new StreamResult(moduleFile)); } finally { monitor.done(); } }
protected void projectChanged() { projectText = projectCombo.getText(); IJavaProject selectedProject = null; for (int i = 0; i < gwtProjects.length; i++) { IJavaProject gwtProject = gwtProjects[i]; if (projectText.equals(gwtProject.getProject().getName())) { selectedProject = gwtProject; break; } } if (selectedProject != null) { try { moduleCombo.removeAll(); List modulesList = Util.findModules(selectedProject); for (Iterator i = modulesList.iterator(); i.hasNext(); ) { IFile file = (IFile) i.next(); IPath projectRelativePath = file.getProjectRelativePath(); String fileName = file.getName(); String moduleName = fileName.substring(0, fileName.length() - Constants.GWT_XML_EXT.length() - 1); moduleCombo.add(projectRelativePath.toString()); moduleCombo.setData(moduleName, file); } int i = modulesList.indexOf(selectedModule); if (i == -1) i = 0; moduleCombo.select(i); moduleText = moduleCombo.getText(); } catch (CoreException e) { Activator.logException(e); } } doStatusUpdate(); }
public void createProjectControls(Composite parent, int nColumns) { Label locationLabel = new Label(parent, SWT.NONE); locationLabel.setText("Project:"); locationLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); projectCombo = new Combo(parent, SWT.BORDER | SWT.READ_ONLY); GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false); data.horizontalSpan = 2; projectCombo.setLayoutData(data); projectCombo.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { projectText = projectCombo.getText(); projectChanged(); } }); gwtProjects = Util.getGwtProjects(); for (int i = 0; i < gwtProjects.length; i++) { IJavaProject gwtProject = gwtProjects[i]; String name = gwtProject.getProject().getName(); projectCombo.add(name); if (name.equals(selectedProject)) projectCombo.select(i); } if (projectCombo.getSelectionIndex() == -1) projectCombo.select(0); new Label(parent, SWT.NONE); }
// @Override public void createType(IProgressMonitor monitor) throws CoreException, InterruptedException { monitor = Util.getNonNullMonitor(monitor); isImplCreation = false; super.createType(monitor); isImplCreation = true; try { addServletToWebXml(new SubProgressMonitor(monitor, 1)); createRemoteServiceImpl(new SubProgressMonitor(monitor, 2)); addServletToGwtXml(new SubProgressMonitor(monitor, 3)); } catch (Exception e) { Activator.logException(e); throw new CoreException(Util.getErrorStatus(e.getMessage())); } }
public void init(IStructuredSelection selection) { if (selection != null && selection instanceof IStructuredSelection) { Object firstElement = ((IStructuredSelection) selection).getFirstElement(); if (firstElement instanceof IFile && Util.isModuleXml((IResource) firstElement)) { this.selectedModule = (IFile) firstElement; this.selectedProject = ((IFile) firstElement).getProject().getName(); } } super.init(selection); }
private void createRemoteServiceImpl(IProgressMonitor monitor) throws IOException, CoreException { monitor = Util.getNonNullMonitor(monitor); try { monitor.beginTask("", 1); IFile remoteServiceImpl = Util.getProject(projectText) .getFile( getPackageFragment() .getResource() .getProjectRelativePath() .append(getTypeName() + "Impl.java")); // modifiedResource = remoteServiceImpl; initTemplateVars(getTypeName(), "", getBasePackageFragment().getElementName()); Util.writeFile("/RemoteService.ServiceImpl.template", remoteServiceImpl, templateVars); } finally { monitor.done(); } }
// @SuppressWarnings("unchecked") private void addServletToWebXml(IProgressMonitor monitor) { monitor = Util.getNonNullMonitor(monitor); try { monitor.beginTask("", 1); WebapplicationFactory factory = WebapplicationFactory.eINSTANCE; Servlet servlet = factory.createServlet(); servlet.setServletName(getTypeName()); ServletType servletType = factory.createServletType(); servletType.setClassName( getPackageFragment().getElementName() + '.' + getTypeName() + "Impl"); servlet.setWebType(servletType); IVirtualComponent component = ComponentCore.createComponent(Util.getProject(projectText)); WebArtifactEdit artifactEdit = WebArtifactEdit.getWebArtifactEditForWrite(component); WebApp webApp = (WebApp) artifactEdit.getContentModelRoot(); webApp.getServlets().add(servlet); ServletMapping mapping = WebapplicationFactory.eINSTANCE.createServletMapping(); mapping.setServlet(servlet); mapping.setName(servlet.getServletName()); mapping.setUrlPattern("/" + serviceUri); webApp.getServletMappings().add(mapping); artifactEdit.saveIfNecessary(monitor); artifactEdit.dispose(); } finally { monitor.done(); } }
// @Override public IPackageFragmentRoot getPackageFragmentRoot() { IPackageFragmentRoot root = null; if (!projectText.equals("")) { // $NON-NLS-1$ try { IJavaProject project = JavaCore.create(Util.getProject(projectText)); IPath moduleXmlPath = new Path(moduleText); root = project.findPackageFragmentRoot( new Path("/").append(projectText).append(moduleXmlPath.segment(0))); // $NON-NLS-1$ } catch (JavaModelException e) { Activator.logException(e); } } return root; }
public IPackageFragment getBasePackageFragment() { IPackageFragment packageFragment = null; if (!projectText.equals("")) { // $NON-NLS-1$ try { IJavaProject project = JavaCore.create(Util.getProject(projectText)); IPath moduleXmlPath = new Path(moduleText); IPath packageFragmentPath = new Path("/") .append(projectText) .append(moduleXmlPath.removeLastSegments(1)); // $NON-NLS-1$ packageFragment = project.findPackageFragment(packageFragmentPath); } catch (JavaModelException e) { Activator.logException(e); } } return packageFragment; }
private File getModuleFile() throws CoreException { IResource resource = Util.getProject(projectText).findMember(moduleText); return resource.getLocation().toFile(); }