use of org.apache.hop.projects.project.ProjectDialog in project hop by apache.
the class ProjectsGuiPlugin method addNewProject.
@GuiToolbarElement(root = HopGui.ID_MAIN_TOOLBAR, id = ID_TOOLBAR_PROJECT_ADD, toolTip = "i18n::HopGui.Toolbar.Project.Add.Tooltip", image = "project-add.svg")
public void addNewProject() {
HopGui hopGui = HopGui.getInstance();
IVariables variables = hopGui.getVariables();
try {
ProjectsConfig config = ProjectsConfigSingleton.getConfig();
String standardProjectsFolder = variables.resolve(config.getStandardProjectsFolder());
String defaultProjectConfigFilename = variables.resolve(config.getDefaultProjectConfigFile());
ProjectConfig projectConfig = new ProjectConfig("", standardProjectsFolder, defaultProjectConfigFilename);
Project project = new Project();
project.setParentProjectName(config.getStandardParentProject());
ProjectDialog projectDialog = new ProjectDialog(hopGui.getShell(), project, projectConfig, variables, false);
String projectName = projectDialog.open();
if (projectName != null) {
config.addProjectConfig(projectConfig);
HopConfig.getInstance().saveToFile();
// Save the project-config.json file as well in the project itself
//
FileObject configFile = HopVfs.getFileObject(projectConfig.getActualProjectConfigFilename(variables));
if (!configFile.exists()) {
// Create the empty configuration file if it does not exists
project.saveToFile();
} else {
// If projects exists load configuration
MessageBox box = new MessageBox(hopGui.getShell(), SWT.ICON_QUESTION | SWT.OK);
box.setText(BaseMessages.getString(PKG, "ProjectGuiPlugin.ProjectExists.Dialog.Header"));
box.setMessage(BaseMessages.getString(PKG, "ProjectGuiPlugin.ProjectExists.Dialog.Message"));
box.open();
project.readFromFile();
}
refreshProjectsList();
selectProjectInList(projectName);
enableHopGuiProject(projectName, project, null);
// Now see if these project contains any local run configurations.
// If not we can add those automatically
//
// First pipeline
//
IHopMetadataSerializer<PipelineRunConfiguration> prcSerializer = hopGui.getMetadataProvider().getSerializer(PipelineRunConfiguration.class);
List<PipelineRunConfiguration> pipelineRunConfigs = prcSerializer.loadAll();
boolean localFound = false;
for (PipelineRunConfiguration pipelineRunConfig : pipelineRunConfigs) {
if (pipelineRunConfig.getEngineRunConfiguration() instanceof LocalPipelineRunConfiguration) {
localFound = true;
}
}
if (!localFound) {
PipelineExecutionConfigurationDialog.createLocalPipelineConfiguration(hopGui.getShell(), prcSerializer);
}
// Then the local workflow runconfig
//
IHopMetadataSerializer<WorkflowRunConfiguration> wrcSerializer = hopGui.getMetadataProvider().getSerializer(WorkflowRunConfiguration.class);
localFound = false;
List<WorkflowRunConfiguration> workflowRunConfigs = wrcSerializer.loadAll();
for (WorkflowRunConfiguration workflowRunConfig : workflowRunConfigs) {
if (workflowRunConfig.getEngineRunConfiguration() instanceof LocalWorkflowRunConfiguration) {
localFound = true;
}
}
if (!localFound) {
MessageBox box = new MessageBox(HopGui.getInstance().getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION);
box.setText(BaseMessages.getString(PKG, "ProjectGuiPlugin.LocalWFRunConfig.Dialog.Header"));
box.setMessage(BaseMessages.getString(PKG, "ProjectGuiPlugin.LocalWFRunConfig.Dialog.Message"));
int anwser = box.open();
if ((anwser & SWT.YES) != 0) {
LocalWorkflowRunConfiguration localWorkflowRunConfiguration = new LocalWorkflowRunConfiguration();
localWorkflowRunConfiguration.setEnginePluginId("Local");
WorkflowRunConfiguration local = new WorkflowRunConfiguration("local", BaseMessages.getString(PKG, "ProjectGuiPlugin.LocalWFRunConfigDescription.Text"), localWorkflowRunConfiguration);
wrcSerializer.save(local);
}
}
// Ask to put the project in a lifecycle environment
//
MessageBox box = new MessageBox(HopGui.getInstance().getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION);
box.setText(BaseMessages.getString(PKG, "ProjectGuiPlugin.Lifecycle.Dialog.Header"));
box.setMessage(BaseMessages.getString(PKG, "ProjectGuiPlugin.Lifecycle.Dialog.Message1") + Const.CR + BaseMessages.getString(PKG, "ProjectGuiPlugin.Lifecycle.Dialog.Message2"));
int anwser = box.open();
if ((anwser & SWT.YES) != 0) {
addNewEnvironment();
}
}
} catch (Exception e) {
new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "ProjectGuiPlugin.AddProject.Error.Dialog.Header"), BaseMessages.getString(PKG, "ProjectGuiPlugin.AddProject.Error.Dialog.Message"), e);
}
}
use of org.apache.hop.projects.project.ProjectDialog in project hop by apache.
the class ProjectsGuiPlugin method editProject.
@GuiToolbarElement(root = HopGui.ID_MAIN_TOOLBAR, id = ID_TOOLBAR_PROJECT_LABEL, type = GuiToolbarElementType.LABEL, label = "i18n::HopGui.Toolbar.Project.Label", toolTip = "i18n::HopGui.Toolbar.Project.Tooltip", separator = true)
public void editProject() {
HopGui hopGui = HopGui.getInstance();
Combo combo = getProjectsCombo();
if (combo == null) {
return;
}
ProjectsConfig config = ProjectsConfigSingleton.getConfig();
String projectName = combo.getText();
ProjectConfig projectConfig = config.findProjectConfig(projectName);
if (projectConfig == null) {
return;
}
try {
Project project = projectConfig.loadProject(hopGui.getVariables());
ProjectDialog projectDialog = new ProjectDialog(hopGui.getShell(), project, projectConfig, hopGui.getVariables(), true);
if (projectDialog.open() != null) {
config.addProjectConfig(projectConfig);
if (!projectName.equals(projectConfig.getProjectName())) {
// Project got renamed
projectName = projectConfig.getProjectName();
// Refresh project reference in hop-config.json
HopConfig.getInstance().saveToFile();
}
project.saveToFile();
refreshProjectsList();
selectProjectInList(projectName);
if (projectDialog.isNeedingProjectRefresh()) {
if (askAboutProjectRefresh(hopGui)) {
// Try to stick to the same environment if we have one selected...
//
LifecycleEnvironment environment = null;
Combo environmentsCombo = getEnvironmentsCombo();
if (environmentsCombo != null) {
environment = config.findEnvironment(environmentsCombo.getText());
}
enableHopGuiProject(projectConfig.getProjectName(), project, environment);
}
}
}
} catch (Exception e) {
new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "ProjectGuiPlugin.EditProject.Error.Dialog.Header"), BaseMessages.getString(PKG, "ProjectGuiPlugin.EditProject.Error.Dialog.Message", projectName), e);
}
}
Aggregations