Java Code Examples for org.eclipse.swt.SWT#ICON_WARNING

The following examples show how to use org.eclipse.swt.SWT#ICON_WARNING . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Translator2.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public boolean quitFile() {
  java.util.List<MessagesStore> changedMessagesStores = store.getChangedMessagesStores();
  if ( !changedMessagesStores.isEmpty() ) {
    MessageBox mb = new MessageBox( shell, SWT.YES | SWT.NO | SWT.ICON_WARNING );
    mb.setMessage( BaseMessages.getString( PKG, "i18nDialog.ChangedFilesWhenExit", changedMessagesStores.size()
      + EMPTY_STRING ) );
    mb.setText( BaseMessages.getString( PKG, "i18nDialog.Warning" ) );

    int answer = mb.open();
    if ( answer == SWT.NO ) {
      return false;
    }
  }

  WindowProperty winprop = new WindowProperty( shell );
  props.setScreen( winprop );
  props.saveProps();

  shell.dispose();
  display.dispose();
  return true;
}
 
Example 2
Source File: AbstractExportAction.java    From erflute with Apache License 2.0 6 votes vote down vote up
protected void save(IEditorPart editorPart, GraphicalViewer viewer) throws Exception {
    final String saveFilePath = getSaveFilePath(editorPart, viewer);
    if (saveFilePath == null) {
        return;
    }
    final File file = new File(saveFilePath);
    if (file.exists()) {
        final MessageBox messageBox =
                new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.ICON_WARNING | SWT.OK | SWT.CANCEL);
        messageBox.setText(DisplayMessages.getMessage("dialog.title.warning"));
        messageBox.setMessage(DisplayMessages.getMessage(getConfirmOverrideMessage()));
        if (messageBox.open() == SWT.CANCEL) {
            return;
        }
    }
    save(editorPart, viewer, saveFilePath);
    refreshProject();
}
 
Example 3
Source File: RepositoryExplorerDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public void editUser( String login ) {
  try {
    IUser uinfo = securityManager.loadUserInfo( login ); // Get UserInfo from repository...
    UserDialog ud = new UserDialog( shell, SWT.NONE, rep, uinfo );
    IUser ui = ud.open();
    if ( !readonly ) {
      if ( ui != null ) {
        securityManager.saveUserInfo( ui );
      }
    } else {
      MessageBox mb = new MessageBox( shell, SWT.ICON_WARNING | SWT.OK );
      mb.setMessage( BaseMessages.getString( PKG, "RepositoryExplorerDialog.User.Edit.NotAllowed.Message" ) );
      mb.setText( BaseMessages.getString( PKG, "RepositoryExplorerDialog.User.Edit.NotAllowed.Title" ) );
      mb.open();
    }
    if ( ui != null && !login.equalsIgnoreCase( ui.getLogin() ) ) {
      refreshTree();
    }

  } catch ( KettleException e ) {
    new ErrorDialog( shell,
      BaseMessages.getString( PKG, "RepositoryExplorerDialog.User.Edit.UnexpectedError.Message.Title" ),
      BaseMessages.getString( PKG, "RepositoryExplorerDialog.User.Edit.UnexpectedError.Message" ), e );
  }
}
 
Example 4
Source File: JobGraph.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public void enableDisableHopsDownstream( boolean enabled ) {
  if ( currentHop == null ) {
    return;
  }
  JobHopMeta before = (JobHopMeta) currentHop.clone();
  currentHop.setEnabled( enabled );
  JobHopMeta after = (JobHopMeta) currentHop.clone();
  spoon.addUndoChange( jobMeta, new JobHopMeta[] { before }, new JobHopMeta[] { after }, new int[] { jobMeta
    .indexOfJobHop( currentHop ) } );

  Set<JobEntryCopy> checkedEntries = enableDisableNextHops( currentHop.getToEntry(), enabled, new HashSet<>() );

  if ( checkedEntries.stream().anyMatch( entry -> jobMeta.hasLoop( entry ) ) ) {
    MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_WARNING );
    mb.setMessage( BaseMessages.getString( PKG, "JobGraph.Dialog.LoopAfterHopEnabled.Message" ) );
    mb.setText( BaseMessages.getString( PKG, "JobGraph.Dialog.LoopAfterHopEnabled.Title" ) );
    mb.open();
  }

  spoon.refreshGraph();
}
 
Example 5
Source File: MongoDbInputDialog.java    From pentaho-mongodb-plugin with Apache License 2.0 6 votes vote down vote up
private boolean checkForUnresolved( MongoDbInputMeta meta, String title ) {

    String query = transMeta.environmentSubstitute( meta.getJsonQuery() );

    boolean notOk = ( query.contains( "${" ) || query.contains( "?{" ) ); //$NON-NLS-1$ //$NON-NLS-2$

    if ( notOk ) {
      ShowMessageDialog
          smd =
          new ShowMessageDialog( shell, SWT.ICON_WARNING | SWT.OK, title, BaseMessages.getString( PKG,
              "MongoDbInputDialog.Warning.Message.MongoQueryContainsUnresolvedVarsFieldSubs" ) ); //$NON-NLS-1$
      smd.open();
    }

    return !notOk;
  }
 
Example 6
Source File: Translator.java    From hop with Apache License 2.0 6 votes vote down vote up
public boolean quitFile() {
  java.util.List<BundleFile> changedBundleFiles = store.getChangedBundleFiles();
  if ( changedBundleFiles.size() > 0 ) {
    MessageBox mb = new MessageBox( shell, SWT.YES | SWT.NO | SWT.ICON_WARNING );
    mb.setMessage( BaseMessages.getString( PKG, "i18nDialog.ChangedFilesWhenExit", changedBundleFiles.size()
      + "" ) );
    mb.setText( BaseMessages.getString( PKG, "i18nDialog.Warning" ) );

    int answer = mb.open();
    if ( answer == SWT.NO ) {
      return false;
    }
  }

  WindowProperty winprop = new WindowProperty( shell );
  props.setScreen( winprop );

  shell.dispose();
  display.dispose();
  return true;
}
 
Example 7
Source File: AbstractExportAction.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
protected void save(IEditorPart editorPart, GraphicalViewer viewer)
		throws Exception {

	String saveFilePath = this.getSaveFilePath(editorPart, viewer);
	if (saveFilePath == null) {
		return;
	}

	File file = new File(saveFilePath);
	if (file.exists()) {
		MessageBox messageBox = new MessageBox(PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow().getShell(), SWT.ICON_WARNING
				| SWT.OK | SWT.CANCEL);
		messageBox.setText(ResourceString
				.getResourceString("dialog.title.warning"));
		messageBox.setMessage(ResourceString.getResourceString(this
				.getConfirmOverrideMessage()));

		if (messageBox.open() == SWT.CANCEL) {
			return;
		}
	}

	this.save(editorPart, viewer, saveFilePath);
	this.refreshProject();
}
 
Example 8
Source File: JobGraph.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public void flipHop() {
  selectionRegion = null;
  JobEntryCopy origFrom = currentHop.getFromEntry();
  JobEntryCopy origTo = currentHop.getToEntry();
  currentHop.setFromEntry( currentHop.getToEntry() );
  currentHop.setToEntry( origFrom );

  boolean cancel = false;
  if ( jobMeta.hasLoop( currentHop.getToEntry() ) ) {
    MessageBox mb = new MessageBox( shell, SWT.OK | SWT.CANCEL | SWT.ICON_WARNING );
    mb.setMessage( BaseMessages.getString( PKG, "JobGraph.Dialog.HopFlipCausesLoop.Message" ) );
    mb.setText( BaseMessages.getString( PKG, "JobGraph.Dialog.HopCausesLoop.Title" ) );
    int choice = mb.open();
    if ( choice == SWT.CANCEL ) {
      cancel = true;
      currentHop.setFromEntry( origFrom );
      currentHop.setToEntry( origTo );
    }
  }
  if ( !cancel ) {
    currentHop.setChanged();
  }
  spoon.refreshGraph();
  spoon.refreshTree();
  spoon.setShellText();
}
 
Example 9
Source File: RepDevMain.java    From RepDev with GNU General Public License v3.0 6 votes vote down vote up
private static void createGUI() {
	// Set Default Size
	if(configRev == CONFIGREV.NEW){
		Config.setSashHSize(150);
		Config.setSashVSize(150);
	}

	mainShell = new MainShell(display);
	mainShell.open();
	createGlobalHotkeys();
	if(configRev != CONFIGREV.NORMAL){
		MessageBox msg = new MessageBox(mainShell.getShell(), SWT.ICON_WARNING);
		msg.setText("RepDev Options");

		if(configRev == CONFIGREV.NEW){
			msg.setMessage("Welcome to RepDev. Please take a few moments to configure your Options.");
		}
		else{
			msg.setMessage("The RepDev Team has added new options.  Please take a few moments to configure them.");
		}
		msg.open();
		OptionsShell.show(mainShell.getShell());
		Config.setRevision(Config.REVISION);
	}
}
 
Example 10
Source File: JobGraph.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * This method enables or disables all the hops between the selected Entries.
 *
 **/
public void enableHopsBetweenSelectedEntries( boolean enabled ) {
  List<JobEntryCopy> list = jobMeta.getSelectedEntries();

  boolean hasLoop = false;

  for ( int i = 0; i < jobMeta.nrJobHops(); i++ ) {
    JobHopMeta hop = jobMeta.getJobHop( i );
    if ( list.contains( hop.getFromEntry() ) && list.contains( hop.getToEntry() ) ) {

      JobHopMeta before = (JobHopMeta) hop.clone();
      hop.setEnabled( enabled );
      JobHopMeta after = (JobHopMeta) hop.clone();
      spoon.addUndoChange( jobMeta, new JobHopMeta[] { before }, new JobHopMeta[] { after }, new int[] { jobMeta
        .indexOfJobHop( hop ) } );
      if ( jobMeta.hasLoop( hop.getToEntry() ) ) {
        hasLoop = true;
      }
    }
  }

  if ( hasLoop && enabled ) {
    MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_WARNING );
    mb.setMessage( BaseMessages.getString( PKG, "JobGraph.Dialog.LoopAfterHopEnabled.Message" ) );
    mb.setText( BaseMessages.getString( PKG, "JobGraph.Dialog.LoopAfterHopEnabled.Title" ) );
    mb.open();
  }

  spoon.refreshGraph();
}
 
Example 11
Source File: HopGuiWorkflowGraph.java    From hop with Apache License 2.0 5 votes vote down vote up
private boolean checkHopLoop( WorkflowHopMeta hop, boolean originalState ) {
  if ( !originalState && ( workflowMeta.hasLoop( hop.getToAction() ) ) ) {
    MessageBox mb = new MessageBox( hopShell(), SWT.CANCEL | SWT.OK | SWT.ICON_WARNING );
    mb.setMessage( BaseMessages.getString( PKG, "WorkflowGraph.Dialog.LoopAfterHopEnabled.Message" ) );
    mb.setText( BaseMessages.getString( PKG, "WorkflowGraph.Dialog.LoopAfterHopEnabled.Title" ) );
    int choice = mb.open();
    if ( choice == SWT.CANCEL ) {
      hop.setEnabled( originalState );
      return false;
    }
  }
  return true;
}
 
Example 12
Source File: Sleak.java    From swt-bling with MIT License 5 votes vote down vote up
void refreshDifference () {
  DeviceData info = display.getDeviceData ();
  if (!info.tracking) {
    MessageBox dialog = new MessageBox (shell, SWT.ICON_WARNING | SWT.OK);
    dialog.setText (shell.getText ());
    dialog.setMessage ("Warning: Device is not tracking resource allocation");
    dialog.open ();
  }
  Object [] newObjects = info.objects;
  Error [] newErrors = info.errors;
  Object [] diffObjects = new Object [newObjects.length];
  Error [] diffErrors = new Error [newErrors.length];
  int count = 0;
  for (int i=0; i<newObjects.length; i++) {
    int index = 0;
    while (index < oldObjects.length) {
      if (newObjects [i] == oldObjects [index]) break;
      index++;
    }
    if (index == oldObjects.length) {
      diffObjects [count] = newObjects [i];
      diffErrors [count] = newErrors [i];
      count++;
    }
  }
  objects = new Object [count];
  errors = new Error [count];
  System.arraycopy (diffObjects, 0, objects, 0, count);
  System.arraycopy (diffErrors, 0, errors, 0, count);
  list.removeAll ();
  text.setText ("");
  canvas.redraw ();
  for (int i=0; i<objects.length; i++) {
    list.add (objectName (objects [i]));
  }
  refreshLabel ();
  layout ();
}
 
Example 13
Source File: MongoDbOutputDialog.java    From pentaho-mongodb-plugin with Apache License 2.0 4 votes vote down vote up
private void setupDBNames() {
  String current = m_dbNameField.getText();
  m_dbNameField.removeAll();

  String hostname = transMeta.environmentSubstitute( m_hostnameField.getText() );

  if ( !Const.isEmpty( hostname ) ) {
    try {
      final MongoDbOutputMeta meta = new MongoDbOutputMeta();
      getInfo( meta );
      List<String> dbNames = new ArrayList<String>();
      MongoClientWrapper wrapper = MongoWrapperUtil.createMongoClientWrapper( meta, transMeta, log );
      try {
        dbNames = wrapper.getDatabaseNames();
      } finally {
        wrapper.dispose();
      }
      for ( String s : dbNames ) {
        m_dbNameField.add( s );
      }

    } catch ( Exception e ) {
      logError( getString( "MongoDbOutputDialog.ErrorMessage.UnableToConnect" ), e ); //$NON-NLS-1$
      new ErrorDialog( shell, getString( "MongoDbOutputDialog.ErrorMessage.UnableToConnect" ),
        //$NON-NLS-1$ //$NON-NLS-2$
        getString( "MongoDbOutputDialog.ErrorMessage.UnableToConnect" ), e ); //$NON-NLS-1$
    }
  } else {
    // popup some feedback
    ShowMessageDialog
      smd =
      new ShowMessageDialog( shell, SWT.ICON_WARNING | SWT.OK,
        getString( "MongoDbOutputDialog.ErrorMessage.MissingConnectionDetails.Title" ),
        BaseMessages.getString( PKG, //$NON-NLS-1$
          "MongoDbOutputDialog.ErrorMessage.MissingConnectionDetails",
          "host name(s)" ) ); //$NON-NLS-1$ //$NON-NLS-2$
    smd.open();
  }

  if ( !Const.isEmpty( current ) ) {
    m_dbNameField.setText( current );
  }
}
 
Example 14
Source File: JobGraph.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void showSaveFileMessage() {
  MessageBox m = new MessageBox( shell, SWT.OK | SWT.ICON_WARNING );
  m.setText( BaseMessages.getString( PKG, "JobLog.Dialog.JobHasChangedSave.Title" ) );
  m.setMessage( BaseMessages.getString( PKG, "JobLog.Dialog.JobHasChangedSave.Message" ) );
  m.open();
}
 
Example 15
Source File: EESpoonPlugin.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private void warnClosingOfOpenTabsBasedOnPerms( Spoon spoon ) throws KettleException {
  Class<PurRepositoryDialog> PKG = PurRepositoryDialog.class;
  // Check to see if there are any open jobs/trans
  Repository repository = spoon.getRepository();
  if ( spoon.getActiveMeta() == null ) {
    return;
  }

  String warningTitle = BaseMessages.getString( PKG, "PurRepository.Dialog.WarnToCloseAllForce.Connect.Title" );
  String warningText =
      BaseMessages.getString( PKG, "PurRepository.Dialog.WarnToCloseAllOptionAdditional.Connect.Message" );
  String additionalWarningText = "";
  int buttons = SWT.OK;

  IAbsSecurityProvider absSecurityProvider =
      (IAbsSecurityProvider) repository.getService( IAbsSecurityProvider.class );
  if ( absSecurityProvider != null ) {
    boolean createPerms = false;
    boolean executePerms = false;
    boolean readPerms = false;
    try {
      createPerms = absSecurityProvider.isAllowed( IAbsSecurityProvider.CREATE_CONTENT_ACTION );
      executePerms = absSecurityProvider.isAllowed( IAbsSecurityProvider.EXECUTE_CONTENT_ACTION );
      readPerms = absSecurityProvider.isAllowed( IAbsSecurityProvider.READ_CONTENT_ACTION );
    } catch ( KettleException e ) {
      // No nothing - we are just checking perms
    }

    // Check to see if display of warning dialog has been disabled
    if ( readPerms && createPerms && executePerms ) {
      warningTitle = BaseMessages.getString( PKG, "PurRepository.Dialog.WarnToCloseAllOption.Connect.Title" );
      warningText = BaseMessages.getString( PKG, "PurRepository.Dialog.WarnToCloseAllOption.Connect.Message" );
      buttons = SWT.YES | SWT.NO | SWT.ICON_INFORMATION;
    } else {
      warningText = BaseMessages.getString( PKG, "PurRepository.Dialog.WarnToCloseAllForce.Connect.Message" );
      if ( createPerms ) {
        additionalWarningText =
            BaseMessages.getString( PKG, "PurRepository.Dialog.WarnToCloseAllForceAdditional.Connect.Message" );
        buttons = SWT.YES | SWT.NO | SWT.ICON_WARNING;
      } else {
        additionalWarningText =
            BaseMessages.getString( PKG, "PurRepository.Dialog.WarnToCloseAllOptionAdditional.Connect.Message" );
        buttons = SWT.OK | SWT.ICON_WARNING;
      }
    }
  }

  MessageBox mb = new MessageBox( spoon.getShell(), buttons );
  mb.setMessage( additionalWarningText.length() != 0 ? warningText + "\n\n" + additionalWarningText : warningText );
  mb.setText( warningTitle );
  final int isCloseAllFiles = mb.open();

  // If user has create content perms, then they can leave the tabs open.
  // Otherwise, we force close the tabs
  if ( ( isCloseAllFiles == SWT.YES ) || ( isCloseAllFiles == SWT.OK ) ) {
    spoon.closeAllFiles();
  }
}
 
Example 16
Source File: RepositoryExplorerDialog.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public boolean delSelectedObjects() {
  TreeItem[] items = wTree.getSelection();
  boolean error = false;

  MessageBox mb = new MessageBox( shell, SWT.ICON_WARNING | SWT.YES | SWT.NO );
  mb
    .setMessage( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Trans.Delete.Confirm.Message1" )
      + ( items.length > 1
        ? BaseMessages.getString( PKG, "RepositoryExplorerDialog.Trans.Delete.Confirm.Message2" )
          + items.length + BaseMessages.getString( PKG, "RepositoryExplorerDialog.Trans.Delete.Confirm.Message3" )
        : BaseMessages.getString( PKG, "RepositoryExplorerDialog.Trans.Delete.Confirm.Message4" ) ) );
  mb.setText( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Trans.Delete.Confirm.Title" ) );
  int answer = mb.open();

  if ( answer != SWT.YES ) {
    return false;
  }

  for ( int i = 0; i < items.length; i++ ) {
    final RepositoryElementMetaInterface repositoryObject = objectMap.get( ConstUI.getTreePath( items[i], 0 ) );
    if ( repositoryObject != null ) {

      try {
        switch ( repositoryObject.getObjectType() ) {
          case TRANSFORMATION:
            rep.deleteTransformation( repositoryObject.getObjectId() );
            break;
          case JOB:
            rep.deleteJob( repositoryObject.getObjectId() );
            break;
          default:
            break;
        }
      } catch ( Exception e ) {
        new ErrorDialog(
          shell,
          BaseMessages.getString( PKG, "RepositoryExplorerDialog.Trans.Delete.ErrorRemoving.Title" ), BaseMessages
            .getString( PKG, "RepositoryExplorerDialog.Trans.Delete.ErrorRemoving.Message" )
            + repositoryObject.getName() + "]", e );
        error = true;
      }
    }
  }
  refreshTree();

  return !error;
}
 
Example 17
Source File: HopGuiWorkflowGraph.java    From hop with Apache License 2.0 4 votes vote down vote up
private void addCandidateAsHop() {
  if ( hopCandidate != null ) {

    // A couple of sanity checks...
    //
    if ( hopCandidate.getFromAction() == null || hopCandidate.getToAction() == null ) {
      return;
    }
    if ( hopCandidate.getFromAction().equals( hopCandidate.getToAction() ) ) {
      return;
    }

    if ( !hopCandidate.getFromAction().evaluates() && hopCandidate.getFromAction().isUnconditional() ) {
      hopCandidate.setUnconditional();
    } else {
      hopCandidate.setConditional();
      int nr = workflowMeta.findNrNextActions( hopCandidate.getFromAction() );

      // If there is one green link: make this one red! (or
      // vice-versa)
      if ( nr == 1 ) {
        ActionCopy jge = workflowMeta.findNextAction( hopCandidate.getFromAction(), 0 );
        WorkflowHopMeta other = workflowMeta.findWorkflowHop( hopCandidate.getFromAction(), jge );
        if ( other != null ) {
          hopCandidate.setEvaluation( !other.getEvaluation() );
        }
      }
    }

    if ( checkIfHopAlreadyExists( workflowMeta, hopCandidate ) ) {
      boolean cancel = false;
      workflowMeta.addWorkflowHop( hopCandidate );
      if ( workflowMeta.hasLoop( hopCandidate.getToAction() ) ) {
        MessageBox mb = new MessageBox( hopGui.getShell(), SWT.OK | SWT.CANCEL | SWT.ICON_WARNING );
        mb.setMessage( BaseMessages.getString( PKG, "WorkflowGraph.Dialog.HopCausesLoop.Message" ) );
        mb.setText( BaseMessages.getString( PKG, "WorkflowGraph.Dialog.HopCausesLoop.Title" ) );
        int choice = mb.open();
        if ( choice == SWT.CANCEL ) {
          workflowMeta.removeWorkflowHop( hopCandidate );
          cancel = true;
        }
      }
      if ( !cancel ) {
        hopGui.undoDelegate.addUndoNew( workflowMeta, new WorkflowHopMeta[] { hopCandidate }, new int[] { workflowMeta
          .indexOfWorkflowHop( hopCandidate ) } );
      }
      clearSettings();
      redraw();
    }
  }
}
 
Example 18
Source File: Sleak.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
void refreshDifference() {
  Display display = canvas.getDisplay();
  DeviceData info = display.getDeviceData();
  if ( !info.tracking ) {
    Shell shell = canvas.getShell();
    MessageBox dialog = new MessageBox( shell, SWT.ICON_WARNING | SWT.OK );
    dialog.setText( shell.getText() );
    dialog.setMessage( "Warning: Device is not tracking resource allocation" );
    dialog.open();
  }
  Object[] newObjects = info.objects;
  Error[] newErrors = info.errors;
  Object[] diffObjects = new Object[newObjects.length];
  Error[] diffErrors = new Error[newErrors.length];
  int count = 0;
  for ( int i = 0; i < newObjects.length; i++ ) {
    int index = 0;
    while ( index < oldObjects.length ) {
      if ( newObjects[i] == oldObjects[index] ) {
        break;
      }
      index++;
    }
    if ( index == oldObjects.length ) {
      diffObjects[count] = newObjects[i];
      diffErrors[count] = newErrors[i];
      count++;
    }
  }
  objects = new Object[count];
  errors = new Error[count];
  System.arraycopy( diffObjects, 0, objects, 0, count );
  System.arraycopy( diffErrors, 0, errors, 0, count );
  list.removeAll();
  text.setText( "" );
  canvas.redraw();
  for ( int i = 0; i < objects.length; i++ ) {
    list.add( objects[i].toString() );
  }
  refreshLabel();
  layout();
}
 
Example 19
Source File: MongoDbOutputDialog.java    From pentaho-mongodb-plugin with Apache License 2.0 4 votes vote down vote up
private void setupCustomWriteConcernNames() {
  String hostname = transMeta.environmentSubstitute( m_hostnameField.getText() );

  if ( !Const.isEmpty( hostname ) ) {
    MongoDbOutputMeta meta = new MongoDbOutputMeta();
    getInfo( meta );
    try {
      MongoClientWrapper wrapper = MongoWrapperUtil.createMongoClientWrapper( meta, transMeta, log );
      List<String> custom = new ArrayList<String>();
      try {
        custom = wrapper.getLastErrorModes();
      } finally {
        wrapper.dispose();
      }

      if ( custom.size() > 0 ) {
        String current = m_writeConcern.getText();
        m_writeConcern.removeAll();

        for ( String s : custom ) {
          m_writeConcern.add( s );
        }

        if ( !Const.isEmpty( current ) ) {
          m_writeConcern.setText( current );
        }
      }
    } catch ( Exception e ) {
      logError( getString( "MongoDbOutputDialog.ErrorMessage.UnableToConnect" ), e ); //$NON-NLS-1$
      new ErrorDialog( shell, getString( "MongoDbOutputDialog.ErrorMessage.UnableToConnect" ),
        //$NON-NLS-1$ //$NON-NLS-2$
        getString( "MongoDbOutputDialog.ErrorMessage.UnableToConnect" ), e ); //$NON-NLS-1$
    }
  } else {
    ShowMessageDialog
      smd =
      new ShowMessageDialog( shell, SWT.ICON_WARNING | SWT.OK,
        getString( "MongoDbOutputDialog.ErrorMessage.MissingConnectionDetails.Title" ),
        BaseMessages.getString( PKG, //$NON-NLS-1$
          "MongoDbOutputDialog.ErrorMessage.MissingConnectionDetails",
          "host name(s)" ) ); //$NON-NLS-1$ //$NON-NLS-2$
    smd.open();
  }
}
 
Example 20
Source File: OdpsOutputDialog.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 4 votes vote down vote up
private void getFields(OdpsOutputMeta meta) {
    if (!Const.isEmpty(m_wEndpoint.getText()) && !Const.isEmpty(m_wAccessId.getText()) && !Const
        .isEmpty(m_wAccessKey.getText()) && !Const.isEmpty(m_wProjectName.getText()) && !Const
        .isEmpty(m_wTableName.getText())) {

        TableSchema schema = MaxcomputeUtil
            .getTableSchema(new AliyunAccount(m_wAccessId.getText(), m_wAccessKey.getText()),
                m_wEndpoint.getText(), m_wProjectName.getText(), m_wTableName.getText());

        List<Column> columns = schema.getColumns();
        List<OdpsField> odpsFields = new ArrayList<OdpsField>();
        for (int i = 0; i < columns.size(); i++) {
            OdpsField field = new OdpsField();
            field.setName(columns.get(i).getName());
            field.setType(columns.get(i).getType().name());
            field.setComment(columns.get(i).getCategoryLabel());
            odpsFields.add(field);
        }

        meta.setOdpsFields(odpsFields);
        RowMetaInterface r = null;
        try {
            r = transMeta.getPrevStepFields(stepname);
        } catch (KettleStepException e) {
            logError(e.getMessage(), e);
        }

        if (r != null) {
            logBasic("prev step fields: " + Arrays.toString(r.getFieldNames()));
            meta.setStreamFields(Arrays.asList(r.getFieldNames()));
        } else {
            logBasic("prev step fields empty!!!");
            meta.setStreamFields(new ArrayList<String>());
        }

        if (meta.getOdpsFields() != null && meta.getStreamFields() != null) {
            m_wFieldsTable.table.clearAll();
            m_wFieldsTable.table.setItemCount(meta.getOdpsFields().size());
            for (int i = 0; i < meta.getOdpsFields().size(); i++) {
                OdpsField odpsField = meta.getOdpsFields().get(i);
                String streamField = "";
                if (meta.getStreamFields().size() > i) {
                    streamField = meta.getStreamFields().get(i);
                }
                TableItem item = m_wFieldsTable.table.getItem(i);
                if (odpsField != null) {
                    if (odpsField.getName() != null)
                        item.setText(1, odpsField.getName());
                    if (streamField != null)
                        item.setText(2, streamField);
                }
            }
        }

    } else {
        // pop up an error dialog
        String missingConDetails = "";
        if (Const.isEmpty(m_wEndpoint.getText())) {
            missingConDetails += " odps endpoint";
        }
        if (Const.isEmpty(m_wAccessId.getText())) {
            missingConDetails += " accessId";
        }
        if (Const.isEmpty(m_wAccessKey.getText())) {
            missingConDetails += " accessKey";
        }
        if (Const.isEmpty(m_wProjectName.getText())) {
            missingConDetails += " project name";
        }
        if (Const.isEmpty(m_wTableName.getText())) {
            missingConDetails += " table name";
        }
        ShowMessageDialog smd = new ShowMessageDialog(shell, SWT.ICON_WARNING | SWT.OK,
            BaseMessages.getString(PKG, "ODPS.ErrorMessage.MissingConnectionDetails.Title"),
            BaseMessages.getString(PKG, "ODPS.ErrorMessage.MissingConnectionDetails",
                missingConDetails));
        smd.open();
    }
}