{
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
ISelection selection = selectionService.getSelection();
NewClassWizard wizard = new NewClassWizard();
String serviceClass = "";
String className = "";
IScriptFolder folder = null;
try {
serviceClass = (String) marker.getAttribute(SymfonyMarker.SERVICE_CLASS);
} catch (CoreException e) {
Logger.logException(e);
}
if (serviceClass == null) {
Logger.log(Logger.ERROR, "Could not retrieve service class to open class dialog");
return;
}
ModelAccess composer = ModelAccess.getInstance();
IResource resource = marker.getResource();
className = serviceClass.substring(serviceClass.lastIndexOf("\\"), serviceClass.length());
String ns = serviceClass.replace(className, "");
IPath folderPath = composer.reverseResolve(resource.getProject(), ns);
if (folderPath == null) {
MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error opening class wizard", "Could not open the New Class wizard. See the workspace log for details");
Logger.log(Logger.ERROR, "Unable to retrieve target folder from composer information");
return;
}
IFolder targetFolder = resource.getProject().getFolder(folderPath);
if (targetFolder.exists() == false) {
try {
targetFolder.create(true, true, new NullProgressMonitor());
} catch (CoreException e) {
e.printStackTrace();
}
}
folder = (IScriptFolder) DLTKCore.create(targetFolder);
wizard.setClassName(className.replace("\\", ""));
wizard.setNamespace(ns);
wizard.setScriptFolder(folder);
if (selection instanceof IStructuredSelection) {
wizard.init(PlatformUI.getWorkbench(), (IStructuredSelection) selectionService.getSelection());
}
WizardDialog dialog = new WizardDialog(shell, wizard);
dialog.create();
dialog.open();