Skip to content

Commit

Permalink
PDI-13867: Able to save job/transformation in the root folder
Browse files Browse the repository at this point in the history
- Add a list of restricted directories to the SelectDirectoryDialog dialog (Disable Ok button if the selection is in the restricted paths list)
- Move the code in TransDialog and JobDialog that sets up the SelectDirectoryDialog into RepositoryDirectoryUI so it can be setup consistently
- Restrict selection of the root when creating the SelectDirectoryDialog so people cant save their transformation or job there.
- Instead of defaulting the repository to a new directory (which points to the root), use the user home directory
- Use current repository directory as default when creating a new Transformation with the mapping step
- Use current repository directory as default when creating a new Transformation with the etl metadata injection step
- Use current repository directory as default when creating a new Transformation with the simple mapping step
- Use current repository directory as default when creating a new Transformation with the single threader step
- Use current repository directory as default when creating a new Transformation with the transformation executor step
- Use current repository directory as default when creating a new Transformation with the transformation job entry
- Use current repository directory as default when creating a new Job with the Job executor step
- Use current repository directory as default when creating a new Job with the job job entry.
  • Loading branch information
rpbouman committed Jul 10, 2015
1 parent 791034f commit e619e8a
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 42 deletions.
29 changes: 10 additions & 19 deletions ui/src/org/pentaho/di/ui/job/dialog/JobDialog.java
Expand Up @@ -74,7 +74,6 @@
import org.pentaho.di.repository.KettleRepositoryLostException;
import org.pentaho.di.repository.ObjectId;
import org.pentaho.di.repository.Repository;
import org.pentaho.di.repository.RepositoryDirectory;
import org.pentaho.di.repository.RepositoryDirectoryInterface;
import org.pentaho.di.ui.core.ConstUI;
import org.pentaho.di.ui.core.PropsUI;
Expand All @@ -88,7 +87,7 @@
import org.pentaho.di.ui.core.widget.FieldDisabledListener;
import org.pentaho.di.ui.core.widget.TableView;
import org.pentaho.di.ui.core.widget.TextVar;
import org.pentaho.di.ui.repository.dialog.SelectDirectoryDialog;
import org.pentaho.di.ui.repository.RepositoryDirectoryUI;
import org.pentaho.di.ui.trans.step.BaseStepDialog;
import org.pentaho.di.ui.util.HelpUtils;

Expand Down Expand Up @@ -549,22 +548,14 @@ private void addJobTab() {
wbDirectory.addSelectionListener( new SelectionAdapter() {
public void widgetSelected( SelectionEvent arg0 ) {
RepositoryDirectoryInterface directoryFrom = jobMeta.getRepositoryDirectory();
if ( directoryFrom == null ) {
directoryFrom = new RepositoryDirectory();
}
ObjectId idDirectoryFrom = directoryFrom.getObjectId();

SelectDirectoryDialog sdd = new SelectDirectoryDialog( shell, SWT.NONE, rep );
RepositoryDirectoryInterface rd = sdd.open();
if ( rd != null ) {
if ( idDirectoryFrom != rd.getObjectId() ) {
// We need to change this in the repository as well!!
// We do this when the user pressed OK
newDirectory = rd;
wDirectory.setText( rd.getPath() );
}
// Else same directory!
RepositoryDirectoryInterface rd = RepositoryDirectoryUI.chooseDirectory( shell, rep, directoryFrom );
if ( rd == null ) {
return;
}
// We need to change this in the repository as well!!
// We do this when the user pressed OK
newDirectory = rd;
wDirectory.setText( rd.getPath() );
}
} );

Expand Down Expand Up @@ -1658,7 +1649,7 @@ public static final Button setShellImage( Shell shell, JobEntryInterface jobEntr
public static PluginInterface getPlugin( JobEntryInterface jobEntryInterface ) {
return PluginRegistry.getInstance().getPlugin( JobEntryPluginType.class, jobEntryInterface );
}

public static Image getImage( Shell shell, PluginInterface plugin ) {
String id = plugin.getIds()[0];
if ( id != null ) {
Expand All @@ -1667,7 +1658,7 @@ public static Image getImage( Shell shell, PluginInterface plugin ) {
}
return null;
}

public void setDirectoryChangeAllowed( boolean directoryChangeAllowed ) {
this.directoryChangeAllowed = directoryChangeAllowed;
}
Expand Down
Expand Up @@ -1140,7 +1140,8 @@ public void shellClosed( ShellEvent e ) {
protected void newJob() {
JobMeta newJobMeta = new JobMeta();
newJobMeta.getDatabases().addAll( jobMeta.getDatabases() );
newJobMeta.setRepository( rep );
newJobMeta.setRepository( jobMeta.getRepository() );
newJobMeta.setRepositoryDirectory( jobMeta.getRepositoryDirectory() );
newJobMeta.setMetaStore( metaStore );

JobDialog jobDialog = new JobDialog( shell, SWT.NONE, newJobMeta, rep );
Expand Down
Expand Up @@ -1160,6 +1160,7 @@ protected void newTransformation() {

newTransMeta.getDatabases().addAll( jobMeta.getDatabases() );
newTransMeta.setRepository( rep );
newTransMeta.setRepositoryDirectory( jobMeta.getRepositoryDirectory() );
newTransMeta.setMetaStore( metaStore );

TransDialog transDialog = new TransDialog( shell, SWT.NONE, newTransMeta, rep );
Expand Down
36 changes: 36 additions & 0 deletions ui/src/org/pentaho/di/ui/repository/RepositoryDirectoryUI.java
Expand Up @@ -24,23 +24,29 @@

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TreeItem;

import org.pentaho.di.core.Const;
import org.pentaho.di.core.exception.KettleDatabaseException;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.repository.ObjectId;
import org.pentaho.di.repository.Repository;
import org.pentaho.di.repository.RepositoryDirectory;
import org.pentaho.di.repository.RepositoryDirectoryInterface;
import org.pentaho.di.repository.RepositoryElementMetaInterface;
import org.pentaho.di.repository.RepositoryObject;
import org.pentaho.di.repository.RepositoryObjectType;
import org.pentaho.di.ui.core.gui.GUIResource;
import org.pentaho.di.ui.repository.dialog.SelectDirectoryDialog;


public class RepositoryDirectoryUI {

Expand Down Expand Up @@ -227,4 +233,34 @@ public static void getDirectoryTree( TreeItem ti, Color dircolor, RepositoryDire
}
}

public static RepositoryDirectoryInterface chooseDirectory( Shell shell, Repository rep, RepositoryDirectoryInterface directoryFrom ) {
if ( rep == null ) {
return null;
}

if ( directoryFrom == null ) {
try {
directoryFrom = rep.getUserHomeDirectory();
} catch ( KettleException ex ) {
directoryFrom = new RepositoryDirectory();
}
}
ObjectId idDirectoryFrom = directoryFrom.getObjectId();

SelectDirectoryDialog sdd = new SelectDirectoryDialog( shell, SWT.NONE, rep );

//PDI-13867: root dir is restricted.
HashSet<String> restrictedPaths = new HashSet<String>();
restrictedPaths.add( directoryFrom.findRoot().getPath() );
sdd.setRestrictedPaths( restrictedPaths );

//TODO: expand and select directoryFrom in the dialog.

RepositoryDirectoryInterface rd = sdd.open();
if ( rd == null || idDirectoryFrom == rd.getObjectId() ) {
return null;
}
return rd;
}

}
Expand Up @@ -22,6 +22,9 @@

package org.pentaho.di.ui.repository.dialog;

import java.util.Collections;
import java.util.Set;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MenuDetectEvent;
import org.eclipse.swt.events.MenuDetectListener;
Expand Down Expand Up @@ -84,6 +87,16 @@ public class SelectDirectoryDialog extends Dialog {

private boolean readOnly;

private Set<String> restrictedPaths = Collections.<String>emptySet();

public void setRestrictedPaths( Set<String> restrictedPaths ) {
this.restrictedPaths = restrictedPaths;
}

private boolean isRestrictedPath( String path ) {
return restrictedPaths.contains( path );
}

public SelectDirectoryDialog( Shell parent, int style, Repository rep ) {
super( parent, style );
this.props = PropsUI.getInstance();
Expand Down Expand Up @@ -176,9 +189,34 @@ public void handleEvent( Event e ) {
} );

wTree.addSelectionListener( new SelectionAdapter() {
public void widgetDefaultSelected( SelectionEvent arg0 ) {
private String getSelectedPath( SelectionEvent selectionEvent ) {
TreeItem treeItem = (TreeItem) selectionEvent.item;
String path;
if ( treeItem.getParentItem() == null ) {
path = treeItem.getText();
} else {
path = ConstUI.getTreePath( treeItem, 0 );
}
return path;
}

private boolean isSelectedPathRestricted( SelectionEvent selectionEvent ) {
String path = getSelectedPath( selectionEvent );
boolean isRestricted = isRestrictedPath( path );
return isRestricted;
}

public void widgetDefaultSelected( SelectionEvent selectionEvent ) {
if ( isSelectedPathRestricted( selectionEvent ) ) {
return;
}
handleOK();
}

public void widgetSelected( SelectionEvent selectionEvent ) {
boolean restricted = isSelectedPathRestricted( selectionEvent );
wOK.setEnabled( !restricted );
}
} );

wRefresh.addListener( SWT.Selection, new Listener() {
Expand Down
30 changes: 9 additions & 21 deletions ui/src/org/pentaho/di/ui/trans/dialog/TransDialog.java
Expand Up @@ -73,7 +73,6 @@
import org.pentaho.di.repository.KettleRepositoryLostException;
import org.pentaho.di.repository.ObjectId;
import org.pentaho.di.repository.Repository;
import org.pentaho.di.repository.RepositoryDirectory;
import org.pentaho.di.repository.RepositoryDirectoryInterface;
import org.pentaho.di.trans.TransDependency;
import org.pentaho.di.trans.TransMeta;
Expand All @@ -93,7 +92,7 @@
import org.pentaho.di.ui.core.widget.FieldDisabledListener;
import org.pentaho.di.ui.core.widget.TableView;
import org.pentaho.di.ui.core.widget.TextVar;
import org.pentaho.di.ui.repository.dialog.SelectDirectoryDialog;
import org.pentaho.di.ui.repository.RepositoryDirectoryUI;
import org.pentaho.di.ui.trans.step.BaseStepDialog;


Expand Down Expand Up @@ -565,26 +564,15 @@ private void addTransTab() {
wbDirectory.setLayoutData( fdbDirectory );
wbDirectory.addSelectionListener( new SelectionAdapter() {
public void widgetSelected( SelectionEvent arg0 ) {
if ( rep != null ) {
RepositoryDirectoryInterface directoryFrom = transMeta.getRepositoryDirectory();
if ( directoryFrom == null ) {
directoryFrom = new RepositoryDirectory();
}
ObjectId idDirectoryFrom = directoryFrom.getObjectId();

SelectDirectoryDialog sdd = new SelectDirectoryDialog( shell, SWT.NONE, rep );
RepositoryDirectoryInterface rd = sdd.open();
if ( rd != null ) {
if ( idDirectoryFrom != rd.getObjectId() ) {
// We need to change this in the repository as well!!
// We do this when the user pressed OK
newDirectory = rd;
wDirectory.setText( rd.getPath() );
}
// else: Same directory!

}
RepositoryDirectoryInterface directoryFrom = transMeta.getRepositoryDirectory();
RepositoryDirectoryInterface rd = RepositoryDirectoryUI.chooseDirectory( shell, rep, directoryFrom );
if ( rd == null ) {
return;
}
// We need to change this in the repository as well!!
// We do this when the user pressed OK
newDirectory = rd;
wDirectory.setText( rd.getPath() );
}
} );

Expand Down
Expand Up @@ -1682,6 +1682,8 @@ private void collectInformation() {
protected void newJob() {
JobMeta newJobMeta = new JobMeta();
newJobMeta.getDatabases().addAll( transMeta.getDatabases() );
newJobMeta.setRepository( transMeta.getRepository() );
newJobMeta.setRepositoryDirectory( transMeta.getRepositoryDirectory() );
JobDialog jobDialog = new JobDialog( shell, SWT.NONE, newJobMeta, repository );
if ( jobDialog.open() != null ) {
Spoon spoon = Spoon.getInstance();
Expand Down
Expand Up @@ -841,6 +841,8 @@ protected void newTransformation() {
TransMeta newTransMeta = new TransMeta();

newTransMeta.getDatabases().addAll( transMeta.getDatabases() );
newTransMeta.setRepository( transMeta.getRepository() );
newTransMeta.setRepositoryDirectory( transMeta.getRepositoryDirectory() );

// Pass some interesting settings from the parent transformations...
//
Expand Down
Expand Up @@ -1351,6 +1351,8 @@ protected void newTransformation() {
TransMeta newTransMeta = new TransMeta();

newTransMeta.getDatabases().addAll( transMeta.getDatabases() );
newTransMeta.setRepository( transMeta.getRepository() );
newTransMeta.setRepositoryDirectory( transMeta.getRepositoryDirectory() );

// Pass some interesting settings from the parent transformations...
//
Expand Down
Expand Up @@ -732,6 +732,8 @@ protected void newTransformation() {
TransMeta newTransMeta = new TransMeta();

newTransMeta.getDatabases().addAll( transMeta.getDatabases() );
newTransMeta.setRepository( transMeta.getRepository() );
newTransMeta.setRepositoryDirectory( transMeta.getRepositoryDirectory() );

// Pass some interesting settings from the parent transformations...
//
Expand Down
Expand Up @@ -1022,6 +1022,8 @@ protected void newTransformation() {
TransMeta newTransMeta = new TransMeta();

newTransMeta.getDatabases().addAll( transMeta.getDatabases() );
newTransMeta.setRepository( transMeta.getRepository() );
newTransMeta.setRepositoryDirectory( transMeta.getRepositoryDirectory() );

// Pass some interesting settings from the parent transformations...
//
Expand Down
Expand Up @@ -1660,6 +1660,12 @@ protected void newTransformation() {
TransMeta newTransMeta = new TransMeta();

newTransMeta.getDatabases().addAll( transMeta.getDatabases() );
newTransMeta.setRepository( transMeta.getRepository() );
newTransMeta.setRepositoryDirectory( transMeta.getRepositoryDirectory() );

// Pass some interesting settings from the parent transformations...
//
newTransMeta.setUsingUniqueConnections( transMeta.isUsingUniqueConnections() );

TransDialog transDialog = new TransDialog( shell, SWT.NONE, newTransMeta, repository );
if ( transDialog.open() != null ) {
Expand Down

0 comments on commit e619e8a

Please sign in to comment.