Search in sources :

Example 1 with UIPartition

use of org.pentaho.di.ui.repository.repositoryexplorer.model.UIPartition in project pentaho-kettle by pentaho.

the class PartitionsController method editPartition.

public void editPartition() {
    String partitionSchemaName = "";
    try {
        Collection<UIPartition> partitions = partitionsTable.getSelectedItems();
        if (partitions != null && !partitions.isEmpty()) {
            // Grab the first item in the list & send it to the partition schema dialog
            PartitionSchema partitionSchema = ((UIPartition) partitions.toArray()[0]).getPartitionSchema();
            partitionSchemaName = partitionSchema.getName();
            // Make sure the partition already exists
            ObjectId partitionId = repository.getPartitionSchemaID(partitionSchema.getName());
            if (partitionId == null) {
                MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
                mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.DoesNotExists.Message", partitionSchemaName));
                mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.Edit.Title"));
                mb.open();
            } else {
                PartitionSchemaDialog partitionDialog = new PartitionSchemaDialog(shell, partitionSchema, repository.readDatabases(), variableSpace);
                if (partitionDialog.open()) {
                    if (partitionSchema.getName() != null && !partitionSchema.getName().equals("")) {
                        repository.insertLogEntry(BaseMessages.getString(RepositoryExplorer.class, "PartitionsController.Message.UpdatingPartition", partitionSchema.getName()));
                        repository.save(partitionSchema, Const.VERSION_COMMENT_EDIT_VERSION, null);
                        if (mainController != null && mainController.getSharedObjectSyncUtil() != null) {
                            mainController.getSharedObjectSyncUtil().synchronizePartitionSchemas(partitionSchema, partitionSchemaName);
                        }
                    } else {
                        MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
                        mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.Edit.InvalidName.Message"));
                        mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.Edit.Title"));
                        mb.open();
                    }
                }
            }
        } else {
            MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
            mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.NoItemSelected.Message"));
            mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.Edit.Title"));
            mb.open();
        }
    } catch (KettleException e) {
        if (mainController == null || !mainController.handleLostRepository(e)) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.Edit.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.Edit.UnexpectedError.Message") + partitionSchemaName + "]", e);
        }
    } finally {
        refreshPartitions();
    }
}
Also used : RepositoryExplorer(org.pentaho.di.ui.repository.repositoryexplorer.RepositoryExplorer) KettleException(org.pentaho.di.core.exception.KettleException) PartitionSchema(org.pentaho.di.partition.PartitionSchema) ObjectId(org.pentaho.di.repository.ObjectId) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) UIPartition(org.pentaho.di.ui.repository.repositoryexplorer.model.UIPartition) PartitionSchemaDialog(org.pentaho.di.ui.partition.dialog.PartitionSchemaDialog) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 2 with UIPartition

use of org.pentaho.di.ui.repository.repositoryexplorer.model.UIPartition in project pentaho-kettle by pentaho.

the class PartitionsController method removePartition.

public void removePartition() {
    String partitionSchemaName = "";
    try {
        Collection<UIPartition> partitions = partitionsTable.getSelectedItems();
        if (partitions != null && !partitions.isEmpty()) {
            for (Object obj : partitions) {
                if (obj != null && obj instanceof UIPartition) {
                    UIPartition partition = (UIPartition) obj;
                    PartitionSchema partitionSchema = partition.getPartitionSchema();
                    partitionSchemaName = partitionSchema.getName();
                    // Make sure the partition to delete exists in the repository
                    ObjectId partitionId = repository.getPartitionSchemaID(partitionSchema.getName());
                    if (partitionId == null) {
                        MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
                        mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.DoesNotExists.Message", partitionSchemaName));
                        mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.Delete.Title"));
                        mb.open();
                    } else {
                        repository.deletePartitionSchema(partitionId);
                        if (mainController != null && mainController.getSharedObjectSyncUtil() != null) {
                            mainController.getSharedObjectSyncUtil().deletePartitionSchema(partitionSchema);
                        }
                    }
                }
            }
        } else {
            MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
            mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.NoItemSelected.Message"));
            mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.Delete.Title"));
            mb.open();
        }
    } catch (KettleException e) {
        if (mainController == null || !mainController.handleLostRepository(e)) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.Delete.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.Delete.UnexpectedError.Message") + partitionSchemaName + "]", e);
        }
    } finally {
        refreshPartitions();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) PartitionSchema(org.pentaho.di.partition.PartitionSchema) ObjectId(org.pentaho.di.repository.ObjectId) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) UIPartition(org.pentaho.di.ui.repository.repositoryexplorer.model.UIPartition) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 3 with UIPartition

use of org.pentaho.di.ui.repository.repositoryexplorer.model.UIPartition in project pentaho-kettle by pentaho.

the class PartitionsController method refreshPartitions.

public void refreshPartitions() {
    if (repository != null) {
        final List<UIPartition> tmpList = new ArrayList<UIPartition>();
        Runnable r = new Runnable() {

            public void run() {
                try {
                    ObjectId[] partitionIdList = repository.getPartitionSchemaIDs(false);
                    for (ObjectId partitionId : partitionIdList) {
                        PartitionSchema partition = repository.loadPartitionSchema(partitionId, null);
                        // Add the partition schema to the list
                        tmpList.add(new UIPartition(partition));
                    }
                } catch (KettleException e) {
                    if (mainController == null || !mainController.handleLostRepository(e)) {
                        // convert to runtime exception so it bubbles up through the UI
                        throw new RuntimeException(e);
                    }
                }
            }
        };
        doWithBusyIndicator(r);
        partitionList.setChildren(tmpList);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ObjectId(org.pentaho.di.repository.ObjectId) PartitionSchema(org.pentaho.di.partition.PartitionSchema) ArrayList(java.util.ArrayList) UIPartition(org.pentaho.di.ui.repository.repositoryexplorer.model.UIPartition)

Aggregations

KettleException (org.pentaho.di.core.exception.KettleException)3 PartitionSchema (org.pentaho.di.partition.PartitionSchema)3 ObjectId (org.pentaho.di.repository.ObjectId)3 UIPartition (org.pentaho.di.ui.repository.repositoryexplorer.model.UIPartition)3 MessageBox (org.eclipse.swt.widgets.MessageBox)2 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)2 ArrayList (java.util.ArrayList)1 PartitionSchemaDialog (org.pentaho.di.ui.partition.dialog.PartitionSchemaDialog)1 RepositoryExplorer (org.pentaho.di.ui.repository.repositoryexplorer.RepositoryExplorer)1