| /** |
| * Copyright (c) 2011, 2015 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Florian Pirchner - Initial implementation |
| */ |
| package org.eclipse.osbp.dsl.entity.xtext.ui.wizards; |
| |
| import org.eclipse.core.resources.IContainer; |
| import org.eclipse.core.resources.IFile; |
| import org.eclipse.core.resources.IResource; |
| import org.eclipse.core.resources.IWorkspaceRoot; |
| import org.eclipse.core.resources.ResourcesPlugin; |
| import org.eclipse.core.runtime.Path; |
| import org.eclipse.jface.viewers.IStructuredSelection; |
| import org.eclipse.ui.IWorkbench; |
| import org.eclipse.ui.IWorkbenchPage; |
| import org.eclipse.ui.IWorkbenchWindow; |
| import org.eclipse.ui.PartInitException; |
| import org.eclipse.ui.ide.IDE; |
| import org.eclipse.ui.internal.ide.DialogUtil; |
| import org.eclipse.ui.internal.wizards.newresource.ResourceMessages; |
| import org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard; |
| |
| |
| @SuppressWarnings("restriction") |
| public class OSBPNewEntityModelWizard extends BasicNewFileResourceWizard { |
| private OSBPNewEntityModelWizardPage mainPage; |
| |
| public OSBPNewEntityModelWizard() { |
| super(); |
| } |
| |
| public void addPages() { |
| mainPage = new OSBPNewEntityModelWizardPage(getSelection()); |
| addPage(mainPage); |
| } |
| |
| public boolean canFinish() { |
| boolean result = super.canFinish(); |
| |
| if (result) { |
| final String containerName = mainPage.getContainerFullPath().toString(); |
| final String fileName = mainPage.getFileName(); |
| |
| IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); |
| IResource resource = root.findMember(new Path(containerName)); |
| if (!resource.exists() || !(resource instanceof IContainer)) { |
| result = false; |
| } |
| IContainer container = (IContainer) resource; |
| final IFile file = container.getFile(new Path(fileName)); |
| if (file.exists()) { |
| result = false; |
| } |
| } |
| return result; |
| } |
| |
| public boolean performFinish() { |
| IFile file = mainPage.createNewFile(); |
| if (file == null) { |
| return false; |
| } |
| |
| selectAndReveal(file); |
| |
| // Open editor on new file. |
| IWorkbenchWindow dw = getWorkbench().getActiveWorkbenchWindow(); |
| try { |
| if (dw != null) { |
| IWorkbenchPage page = dw.getActivePage(); |
| if (page != null) { |
| IDE.openEditor(page, file, true); |
| } |
| } |
| } catch (PartInitException e) { |
| DialogUtil.openError(dw.getShell(), |
| ResourceMessages.FileResource_errorMessage, e.getMessage(), |
| e); |
| } |
| |
| return true; |
| } |
| |
| public void init(IWorkbench workbench, IStructuredSelection currentSelection) { |
| super.init(workbench, currentSelection); |
| } |
| |
| protected void initializeDefaultPageImageDescriptor() { |
| super.initializeDefaultPageImageDescriptor(); |
| } |
| } |