Search in sources :

Example 1 with LifecycleEnvironment

use of org.apache.hop.projects.environment.LifecycleEnvironment in project hop by apache.

the class ProjectsGuiPlugin method deleteSelectedEnvironment.

@GuiToolbarElement(root = HopGui.ID_MAIN_TOOLBAR, id = ID_TOOLBAR_ENVIRONMENT_DELETE, toolTip = "i18n::HopGui.Toolbar.Environment.Delete.Tooltip", image = "environment-delete.svg", separator = true)
public void deleteSelectedEnvironment() {
    Combo combo = getEnvironmentsCombo();
    if (combo == null) {
        return;
    }
    String environmentName = combo.getText();
    if (StringUtils.isEmpty(environmentName)) {
        return;
    }
    ProjectsConfig config = ProjectsConfigSingleton.getConfig();
    LifecycleEnvironment environment = config.findEnvironment(environmentName);
    if (environment == null) {
        return;
    }
    MessageBox box = new MessageBox(HopGui.getInstance().getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION);
    box.setText(BaseMessages.getString(PKG, "ProjectGuiPlugin.DeleteEnvironment.Dialog.Header"));
    box.setMessage(BaseMessages.getString(PKG, "ProjectGuiPlugin.DeleteEnvironment.Dialog.Message1", environmentName) + Const.CR + BaseMessages.getString(PKG, "ProjectGuiPlugin.DeleteEnvironment.Dialog.Message2", environment.getProjectName()));
    int anwser = box.open();
    if ((anwser & SWT.YES) != 0) {
        try {
            config.removeEnvironment(environmentName);
            ProjectsConfigSingleton.saveConfig();
            refreshEnvironmentsList();
            selectEnvironmentInList(null);
        } catch (Exception e) {
            new ErrorDialog(HopGui.getInstance().getShell(), BaseMessages.getString(PKG, "ProjectGuiPlugin.DeleteEnvironment.Error.Dialog.Header"), BaseMessages.getString(PKG, "ProjectGuiPlugin.DeleteEnvironment.Error.Dialog.Message", environmentName), e);
        }
    }
}
Also used : LifecycleEnvironment(org.apache.hop.projects.environment.LifecycleEnvironment) ProjectsConfig(org.apache.hop.projects.config.ProjectsConfig) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) Combo(org.eclipse.swt.widgets.Combo) HopExtensionPoint(org.apache.hop.core.extension.HopExtensionPoint) HopException(org.apache.hop.core.exception.HopException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) MessageBox(org.eclipse.swt.widgets.MessageBox) GuiToolbarElement(org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)

Example 2 with LifecycleEnvironment

use of org.apache.hop.projects.environment.LifecycleEnvironment in project hop by apache.

the class ProjectsGuiPlugin method addNewEnvironment.

@GuiToolbarElement(root = HopGui.ID_MAIN_TOOLBAR, id = ID_TOOLBAR_ENVIRONMENT_ADD, toolTip = "i18n::HopGui.Toolbar.Environment.Add.Tooltip", image = "environment-add.svg")
public void addNewEnvironment() {
    HopGui hopGui = HopGui.getInstance();
    try {
        ProjectsConfig config = ProjectsConfigSingleton.getConfig();
        // The default is the active project
        String projectName = getProjectsCombo().getText();
        LifecycleEnvironment environment = new LifecycleEnvironment(null, "", projectName, new ArrayList<>());
        LifecycleEnvironmentDialog dialog = new LifecycleEnvironmentDialog(hopGui.getShell(), environment, hopGui.getVariables());
        String environmentName = dialog.open();
        if (environmentName != null) {
            config.addEnvironment(environment);
            ProjectsConfigSingleton.saveConfig();
            refreshEnvironmentsList();
            selectEnvironmentInList(environmentName);
            ProjectConfig projectConfig = config.findProjectConfig(projectName);
            if (projectConfig != null) {
                Project project = projectConfig.loadProject(hopGui.getVariables());
                enableHopGuiProject(projectName, project, environment);
            }
        }
    } catch (Exception e) {
        new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "ProjectGuiPlugin.AddEnvironment.Error.Dialog.Header"), BaseMessages.getString(PKG, "ProjectGuiPlugin.AddEnvironment.Error.Dialog.Message"), e);
    }
}
Also used : ProjectConfig(org.apache.hop.projects.project.ProjectConfig) Project(org.apache.hop.projects.project.Project) LifecycleEnvironment(org.apache.hop.projects.environment.LifecycleEnvironment) ProjectsConfig(org.apache.hop.projects.config.ProjectsConfig) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) LifecycleEnvironmentDialog(org.apache.hop.projects.environment.LifecycleEnvironmentDialog) HopException(org.apache.hop.core.exception.HopException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) HopGui(org.apache.hop.ui.hopgui.HopGui) GuiToolbarElement(org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)

Example 3 with LifecycleEnvironment

use of org.apache.hop.projects.environment.LifecycleEnvironment in project hop by apache.

the class ProjectsGuiPlugin method selectProject.

@GuiToolbarElement(root = HopGui.ID_MAIN_TOOLBAR, id = ID_TOOLBAR_PROJECT_COMBO, type = GuiToolbarElementType.COMBO, comboValuesMethod = "getProjectsList", extraWidth = 200, toolTip = "i18n::HopGui.Toolbar.ProjectsList.Tooltip")
public void selectProject() {
    HopGui hopGui = HopGui.getInstance();
    Combo combo = getProjectsCombo();
    if (combo == null) {
        return;
    }
    String projectName = combo.getText();
    if (StringUtils.isEmpty(projectName)) {
        return;
    }
    ProjectsConfig config = ProjectsConfigSingleton.getConfig();
    ProjectConfig projectConfig = config.findProjectConfig(projectName);
    // What is the last used environment?
    // 
    LifecycleEnvironment environment = null;
    // 
    try {
        List<AuditEvent> environmentAuditEvents = AuditManager.findEvents(ProjectsUtil.STRING_PROJECTS_AUDIT_GROUP, ProjectsUtil.STRING_ENVIRONMENT_AUDIT_TYPE, "open", 100, true);
        for (AuditEvent auditEvent : environmentAuditEvents) {
            String environmentName = auditEvent.getName();
            if (StringUtils.isNotEmpty(environmentName)) {
                environment = config.findEnvironment(environmentName);
                // 
                if (projectName.equals(environment.getProjectName())) {
                    // We found what we've been looking for
                    break;
                } else {
                    // The project doesn't to the last selected environment
                    // Since we selected the project it is the driver of the selection.
                    // Keep looking.
                    // 
                    environment = null;
                }
            }
        }
    } catch (Exception e) {
        LogChannel.UI.logError("Error reading the last used environment from the audit logs", e);
    }
    // 
    if (environment == null) {
        List<LifecycleEnvironment> environments = config.findEnvironmentsOfProject(projectName);
        if (!environments.isEmpty()) {
            environment = environments.get(0);
        }
    }
    try {
        Project project = projectConfig.loadProject(hopGui.getVariables());
        if (project != null) {
            enableHopGuiProject(projectName, project, environment);
        } else {
            hopGui.getLog().logError("Unable to find project '" + projectName + "'");
        }
    } catch (Exception e) {
        new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "ProjectGuiPlugin.ChangeProject.Error.Dialog.Header"), BaseMessages.getString(PKG, "ProjectGuiPlugin.ChangeProject.Error.Dialog.Message", projectName), e);
    }
}
Also used : ProjectConfig(org.apache.hop.projects.project.ProjectConfig) Project(org.apache.hop.projects.project.Project) LifecycleEnvironment(org.apache.hop.projects.environment.LifecycleEnvironment) ProjectsConfig(org.apache.hop.projects.config.ProjectsConfig) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) Combo(org.eclipse.swt.widgets.Combo) AuditEvent(org.apache.hop.history.AuditEvent) HopException(org.apache.hop.core.exception.HopException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) HopGui(org.apache.hop.ui.hopgui.HopGui) GuiToolbarElement(org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)

Example 4 with LifecycleEnvironment

use of org.apache.hop.projects.environment.LifecycleEnvironment in project hop by apache.

the class ProjectsGuiPlugin method editEnvironment.

// ////////////////////////////////////////////////////////////////////////////////
// Environment toolbar items...
// 
// ////////////////////////////////////////////////////////////////////////////////
@GuiToolbarElement(root = HopGui.ID_MAIN_TOOLBAR, id = ID_TOOLBAR_ENVIRONMENT_LABEL, type = GuiToolbarElementType.LABEL, label = "i18n::HopGui.Toolbar.Environment.Label", toolTip = "i18n::HopGui.Toolbar.Environment.Tooltip", separator = true)
public void editEnvironment() {
    HopGui hopGui = HopGui.getInstance();
    Combo combo = getEnvironmentsCombo();
    if (combo == null) {
        return;
    }
    ProjectsConfig config = ProjectsConfigSingleton.getConfig();
    String environmentName = combo.getText();
    if (StringUtils.isEmpty(environmentName)) {
        return;
    }
    LifecycleEnvironment environment = config.findEnvironment(environmentName);
    if (environment == null) {
        return;
    }
    try {
        LifecycleEnvironmentDialog dialog = new LifecycleEnvironmentDialog(hopGui.getShell(), environment, hopGui.getVariables());
        if (dialog.open() != null) {
            config.addEnvironment(environment);
            ProjectsConfigSingleton.saveConfig();
            refreshEnvironmentsList();
            selectEnvironmentInList(environmentName);
        }
        // 
        if (dialog.isNeedingEnvironmentRefresh() && askAboutProjectRefresh(hopGui)) {
            // Refresh the loaded environment
            // 
            selectEnvironment();
        }
    } catch (Exception e) {
        new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "ProjectGuiPlugin.EditEnvironment.Error.Dialog.Header"), BaseMessages.getString(PKG, "ProjectGuiPlugin.EditEnvironment.Error.Dialog.Message", environmentName), e);
    }
}
Also used : LifecycleEnvironment(org.apache.hop.projects.environment.LifecycleEnvironment) ProjectsConfig(org.apache.hop.projects.config.ProjectsConfig) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) Combo(org.eclipse.swt.widgets.Combo) LifecycleEnvironmentDialog(org.apache.hop.projects.environment.LifecycleEnvironmentDialog) HopException(org.apache.hop.core.exception.HopException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) HopGui(org.apache.hop.ui.hopgui.HopGui) GuiToolbarElement(org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)

Example 5 with LifecycleEnvironment

use of org.apache.hop.projects.environment.LifecycleEnvironment 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);
    }
}
Also used : ProjectConfig(org.apache.hop.projects.project.ProjectConfig) Project(org.apache.hop.projects.project.Project) ProjectDialog(org.apache.hop.projects.project.ProjectDialog) LifecycleEnvironment(org.apache.hop.projects.environment.LifecycleEnvironment) ProjectsConfig(org.apache.hop.projects.config.ProjectsConfig) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) Combo(org.eclipse.swt.widgets.Combo) HopException(org.apache.hop.core.exception.HopException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) HopGui(org.apache.hop.ui.hopgui.HopGui) GuiToolbarElement(org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)

Aggregations

ProjectsConfig (org.apache.hop.projects.config.ProjectsConfig)8 LifecycleEnvironment (org.apache.hop.projects.environment.LifecycleEnvironment)8 HopException (org.apache.hop.core.exception.HopException)7 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)7 IOException (java.io.IOException)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 GuiToolbarElement (org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)6 HopGui (org.apache.hop.ui.hopgui.HopGui)6 Combo (org.eclipse.swt.widgets.Combo)6 Project (org.apache.hop.projects.project.Project)5 ProjectConfig (org.apache.hop.projects.project.ProjectConfig)5 AuditEvent (org.apache.hop.history.AuditEvent)2 LifecycleEnvironmentDialog (org.apache.hop.projects.environment.LifecycleEnvironmentDialog)2 HopExtensionPoint (org.apache.hop.core.extension.HopExtensionPoint)1 ProjectDialog (org.apache.hop.projects.project.ProjectDialog)1 GuiToolbarWidgets (org.apache.hop.ui.core.gui.GuiToolbarWidgets)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1