blob: d73c98fb3ee658053259cfa4358ff566185388a2 [file] [log] [blame]
/*
* Copyright (c) Robert Bosch GmbH. All rights reserved.
*/
package org.eclipse.blockchain.ui.wizard;
import java.io.IOException;
import org.eclipse.blockchain.core.BlockchainCore;
import org.eclipse.blockchain.core.ProjectCreator;
import org.eclipse.blockchain.core.SecoBlocksPreferenceConstants;
import org.eclipse.blockchain.ui.Activator;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import org.osgi.service.prefs.BackingStoreException;
/**
* @author ADG5COB
*/
public class EthereumProjectWizard extends Wizard implements INewWizard {
private EthereumProjectWizardPage ePWP = null;
/**
* {@inheritDoc}
*/
@Override
public void init(final IWorkbench workbench, final IStructuredSelection selection) {
setWindowTitle("Ethereum Project Creation");
this.ePWP = new EthereumProjectWizardPage("Ethereum Project Creation");
}
/**
* {@inheritDoc}
*/
@Override
public boolean performFinish() {
try {
String projectCreationResponse = "";
// check if it is an existing/new project
if (this.ePWP.isNewProjectToBeCreated()) {
// New project
String projectNameString = this.ePWP.getProjectNameString();
projectCreationResponse =
ProjectCreator.getInstance().createNewProject(projectNameString, this.ePWP.getNewProjectPath());
ResourcesPlugin.getWorkspace().getRoot().getProject(projectNameString).refreshLocal(IResource.DEPTH_ONE,
new NullProgressMonitor());
if (projectCreationResponse.equals("")) {
InstanceScope.INSTANCE.getNode(SecoBlocksPreferenceConstants.SECOBLOCKS_PREF_NODE)
.put(SecoBlocksPreferenceConstants.SOLIDITY_COMPILER_PREF_KEY, this.ePWP.getSolcPathFromTextBox());
InstanceScope.INSTANCE.getNode(SecoBlocksPreferenceConstants.SECOBLOCKS_PREF_NODE).flush();
IFile solFile = ProjectCreator.getInstance().getFirstMatchingSolFile(projectNameString);
if (solFile != null) {
IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), solFile);
}
return true;
}
}
else {
String ethCheck = ProjectCreator.getInstance().isItAnEthereumProject(this.ePWP.getExistingProjectPath());
if (ethCheck.isEmpty()) {
// existing project
projectCreationResponse =
ProjectCreator.getInstance().createExistingProject(this.ePWP.getExistingProjectPath());
if (projectCreationResponse.equals("")) {
return true;
}
}
else {
if (ethCheck.equals("Not Ethereum project")) {
if (MessageDialog.openQuestion(getShell(), "Project Not Ethereum Project",
"Only if Ethereum nature is present you can import it. Would you like to add it???")) {
projectCreationResponse =
ProjectCreator.getInstance().createExistingProject(this.ePWP.getExistingProjectPath());
if (projectCreationResponse.equals("")) {
return true;
}
}
else {
return true;
}
}
else {
showError("Project Creation Error", ethCheck);
}
}
}
showError("Project Creation Error", projectCreationResponse);
}
catch (IOException | CoreException | BackingStoreException e) {
BlockchainCore.getInstance().logException(Activator.PLUGIN_ID, e.getMessage(), e);
}
return false;
}
private void showError(final String title, final String message) {
MessageDialog.openError(Display.getDefault().getActiveShell(), title, message);
}
/**
* {@inheritDoc}
*/
@Override
public void addPages() {
super.addPages();
addPage(this.ePWP);
}
}