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

The following examples show how to use org.eclipse.swt.SWT#OPEN . 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: ParamsAttachManager.java    From http4e with Apache License 2.0 6 votes vote down vote up
public void widgetSelected( SelectionEvent event){
   FileDialog fd = new FileDialog(st.getShell(), SWT.OPEN);
   fd.setText("Add File Parameter");
   fd.setFilterExtensions(CoreConstants.FILE_FILTER_EXT);
   String file = fd.open();

   if (file != null) {
      if (manager.isMultipart()) {
         st.setText(st.getText() + CoreConstants.FILE_PREFIX + file);
      } else {
         try {
            st.setText(readFileAsString(file));
         } catch (IOException e) {
            // ignore
         }
      }
      // model.fireExecute(new ModelEvent(ModelEvent.BODY_FOCUS_LOST,
      // model));
      // // force body to refresh itself
      // model.fireExecute(new ModelEvent(ModelEvent.PARAMS_FOCUS_LOST,
      // model));
   }
}
 
Example 2
Source File: DFSActionImpl.java    From hadoop-gpu with Apache License 2.0 6 votes vote down vote up
/**
 * Implement the import action (upload files from the current machine to
 * HDFS)
 * 
 * @param object
 * @throws SftpException
 * @throws JSchException
 * @throws InvocationTargetException
 * @throws InterruptedException
 */
private void uploadFilesToDFS(IStructuredSelection selection)
    throws InvocationTargetException, InterruptedException {

  // Ask the user which files to upload
  FileDialog dialog =
      new FileDialog(Display.getCurrent().getActiveShell(), SWT.OPEN
          | SWT.MULTI);
  dialog.setText("Select the local files to upload");
  dialog.open();

  List<File> files = new ArrayList<File>();
  for (String fname : dialog.getFileNames())
    files.add(new File(dialog.getFilterPath() + File.separator + fname));

  // TODO enable upload command only when selection is exactly one folder
  List<DFSFolder> folders = filterSelection(DFSFolder.class, selection);
  if (folders.size() >= 1)
    uploadToDFS(folders.get(0), files);
}
 
Example 3
Source File: DirectoryDialogButtonListenerFactory.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public static final SelectionAdapter getSelectionAdapter( final Shell shell, final Text destination ) {
  // Listen to the Browse... button
  return new SelectionAdapter() {
    public void widgetSelected( SelectionEvent e ) {
      DirectoryDialog dialog = new DirectoryDialog( shell, SWT.OPEN );
      if ( destination.getText() != null ) {
        String fpath = destination.getText();
        // String fpath = StringUtil.environmentSubstitute(destination.getText());
        dialog.setFilterPath( fpath );
      }

      if ( dialog.open() != null ) {
        String str = dialog.getFilterPath();
        destination.setText( str );
      }
    }
  };
}
 
Example 4
Source File: TMX2TXTConverterDialog.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 选择TMX文件
 */
private void selecteTMXFile() {
	FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
	String[] extensions = { "*.tmx", "*.*" };
	fd.setFilterExtensions(extensions);
	String[] names = { Messages.getString("dialog.TMX2TXTConverterDialog.TMXNames1"),
			Messages.getString("dialog.TMX2TXTConverterDialog.TMXNames2") };
	fd.setFilterNames(names);
	String file = fd.open();
	if (file != null) {
		tmxTxt.setText(file);
		if (txtTxt.getText().equals("")) {
			txtTxt.setText(file.substring(0, file.lastIndexOf(".")) + ".txt");
		}
	}
}
 
Example 5
Source File: SimpleChatUI.java    From jReto with MIT License 6 votes vote down vote up
public void sendFile() {
	if (this.selectedPeer == null) return;
	
	FileDialog fd = new FileDialog(shlSimpleChatExample, SWT.OPEN);
       fd.setText("Choose a file to send");
       String selected = fd.open();

       if (selected == null) return;
       
       Path path = FileSystems.getDefault().getPath(selected);
       OpenOption[] read = { StandardOpenOption.READ };
       try {
		FileChannel fileChannel = FileChannel.open(path, read);
				
		this.selectedPeer.sendFile(fileChannel, path.getFileName().toString(), (int)fileChannel.size());
       } catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example 6
Source File: FileChooser.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private static String getDialogText(int swtFlag) {
	switch (swtFlag) {
	case SWT.OPEN:
		return M.Import;
	case SWT.SAVE:
		return M.SelectTheExportFile;
	default:
		return "";
	}
}
 
Example 7
Source File: OpenFileFlow.java    From Universal-FE-Randomizer with MIT License 5 votes vote down vote up
@Override
public void handleEvent(Event event) {
	// TODO Auto-generated method stub
	FileDialog openDialog = new FileDialog(parent, SWT.OPEN);
	openDialog.setFilterExtensions(new String[] {"*.gba;*.smc;*.sfc;*.iso", "*"});
	openDialog.setFilterNames(new String[] {"*.gba, *.smc, *.sfc, *.iso", "All Files (*.*)"});
	delegate.onSelectedFile(openDialog.open());
}
 
Example 8
Source File: TMX2TXTConverterDialog.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 选择TXT文件 ;
 */
private void selecteTXTFile() {
	FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
	String[] extensions = { "*.txt", "*.*" };
	fd.setFilterExtensions(extensions);
	String[] names = { Messages.getString("dialog.TMX2TXTConverterDialog.TXTNames1"),
			Messages.getString("dialog.TMX2TXTConverterDialog.TXTNames2") };
	fd.setFilterNames(names);
	String file = fd.open();
	if (file != null) {
		txtTxt.setText(file);
	}
}
 
Example 9
Source File: PTFileEditor.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @see org.eclipse.nebula.widgets.opal.propertytable.editor.PTChooserEditor#openWindow(org.eclipse.nebula.widgets.opal.propertytable.PTWidget,
 *      org.eclipse.swt.widgets.Item, org.eclipse.nebula.widgets.opal.propertytable.PTProperty)
 */
@Override
protected void openWindow(final PTWidget widget, final Item item, final PTProperty property) {
	final FileDialog dialog = new FileDialog(widget.getWidget().getShell(), SWT.OPEN);
	final String result = dialog.open();
	if (result != null) {
		if (item instanceof TableItem) {
			((TableItem) item).setText(1, result);
		} else {
			((TreeItem) item).setText(1, result);
		}
		property.setValue(result);
	}

}
 
Example 10
Source File: FileBrowserField.java    From eclipsegraphviz with Eclipse Public License 1.0 5 votes vote down vote up
private File getFile(File startingDirectory) {
    FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
    if (startingDirectory != null) {
        dialog.setFileName(startingDirectory.getPath());
    }
    String file = dialog.open();
    if (file != null) {
        file = file.trim();
        if (file.length() > 0) {
            return new File(file);
        }
    }

    return null;
}
 
Example 11
Source File: LoadXmlAction.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private FileDialog createFileDialog(IProject project) {
    FileDialog fileDialog = new FileDialog(FindbugsPlugin.getShell(), SWT.APPLICATION_MODAL | SWT.OPEN);
    fileDialog.setText("Select bug result xml for project: " + project.getName());
    String initialFileName = getDialogSettings().get(LOAD_XML_PATH_KEY);
    if (initialFileName != null && initialFileName.length() > 0) {
        File initialFile = new File(initialFileName);
        // have to check if exists, otherwise crazy GTK will ignore preset
        // filter
        if (initialFile.exists()) {
            fileDialog.setFileName(initialFile.getName());
        }
        fileDialog.setFilterPath(initialFile.getParent());
    }
    return fileDialog;
}
 
Example 12
Source File: ImportFileWizardPage.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected String openFileDialog() {
    final FileDialog fd = new FileDialog(getShell(), SWT.OPEN | SWT.SINGLE);
    fd.setText(Messages.importProcessTitle);

    fd.setFilterPath(getLastPath());

    final String filterExtensions = importFileData.getImporterFactory().getFilterExtensions();

    final String[] filterExt = filterExtensions.split(",");
    fd.setFilterExtensions(filterExt);
    return fd.open();
}
 
Example 13
Source File: NodePreferencePage.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private IPath getDirectory()
{
	DirectoryDialog fileDialog = new DirectoryDialog(getShell(), SWT.OPEN | SWT.SHEET);
	fileDialog.setMessage(MessageFormat.format(Messages.NodePreferencePage_nodejsDirSelectionMessage,
			NODE_JS_ROOT_NAME));
	String dir = fileDialog.open();
	if (!StringUtil.isEmpty(dir))
	{
		return Path.fromOSString(dir);
	}
	return null;
}
 
Example 14
Source File: AttachManager.java    From http4e with Apache License 2.0 5 votes vote down vote up
public void widgetSelected( SelectionEvent event){
      FileDialog fd = new FileDialog(parent.getShell(), SWT.OPEN);
      fd.setText("Add File Content to Body");
      // fd.setFilterPath("C:/");
      fd.setFilterExtensions(CoreConstants.FILE_FILTER_EXT);
      String file = fd.open();
      
      if (file != null) {
         parent.setText(CoreConstants.FILE_PREFIX + file);
         model.fireExecute(new ModelEvent(ModelEvent.BODY_FOCUS_LOST, model));
//       force body to refresh itself
         model.fireExecute(new ModelEvent(ModelEvent.PARAMS_FOCUS_LOST, model)); 
      }
   }
 
Example 15
Source File: OpenFileAction.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void run( )
{
	FileDialog dialog = new FileDialog( fWindow.getShell( ), SWT.OPEN
			| SWT.MULTI );
	dialog.setText( DesignerWorkbenchMessages.Dialog_openFile );
	dialog.setFilterExtensions( filterExtensions );
	dialog.setFilterPath( ResourcesPlugin.getWorkspace( )
			.getRoot( )
			.getProjectRelativePath( )
			.toOSString( ) );
	dialog.open( );
	String[] names = dialog.getFileNames( );

	if ( names != null )
	{
		String fFilterPath = dialog.getFilterPath( );

		int numberOfFilesNotFound = 0;
		StringBuffer notFound = new StringBuffer( );
		for ( int i = 0; i < names.length; i++ )
		{
			File file = new File( fFilterPath + File.separator + names[i] );
			if ( file.exists( ) )
			{
				IWorkbenchPage page = fWindow.getActivePage( );
				IEditorInput input = new ReportEditorInput( file );
				IEditorDescriptor editorDesc = getEditorDescriptor( input,
						OpenStrategy.activateOnOpen( ) );
				try
				{
					page.openEditor( input, editorDesc.getId( ) );
				}
				catch ( Exception e )
				{
					ExceptionUtil.handle( e );
				}
			}
			else
			{
				if ( ++numberOfFilesNotFound > 1 )
					notFound.append( '\n' );
				notFound.append( file.getName( ) );
			}
		}
		if ( numberOfFilesNotFound > 0 )
		{
			// String msgFmt= numberOfFilesNotFound == 1 ?
			// TextEditorMessages.OpenExternalFileAction_message_fileNotFound
			// :
			// TextEditorMessages.OpenExternalFileAction_message_filesNotFound;
			// String msg= MessageFormat.format(msgFmt, new Object[] {
			// notFound.toString() });
			// MessageDialog.openError(fWindow.getShell(),
			// TextEditorMessages.OpenExternalFileAction_title, msg);
		}
	}
}
 
Example 16
Source File: NewGraphMLOptionPart.java    From depan with Apache License 2.0 4 votes vote down vote up
/**
 * Open a directory and write the name in the given {@link Text} object.
 */
private void handleBrowse() {
  FileDialog dialog = new FileDialog(containingPage.getShell(), SWT.OPEN);
  dialog.setFilterExtensions(POM_FILTER);
  pathEntry.setText(dialog.open());
}
 
Example 17
Source File: PerspektiveImportHandler.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException{
	try {
		EModelService modelService = getService(EModelService.class);
		FileDialog dialog = new FileDialog(UiDesk.getTopShell(), SWT.OPEN);
		dialog.setFilterNames(new String[] {
			"XMI", "XML (Legacy)"
		});
		dialog.setFilterExtensions(new String[] {
			"*.xmi", "*.xml"
		});
		
		dialog.setFilterPath(CoreHub.getWritableUserDir().getAbsolutePath()); // Windows path
		
		String path = dialog.open();
		if (path != null) {
			IPerspectiveDescriptor createdPd = null;
			if (path.toLowerCase().endsWith("xml")) {
				// legacy
				
				MPerspective mPerspective = modelService.createModelElement(MPerspective.class);
				// the workbench window must be on top - otherwise the exception 'Application does not have an active window' occurs
				PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().open();
				List<String> fastViewIds =
					perspectiveImportService.createPerspectiveFromLegacy(path, mPerspective);
				createdPd = savePerspectiveToRegistryLegacy(mPerspective);
				perspectiveImportService.openPerspective(createdPd);
				switchToPerspectiveLegacy(mPerspective, fastViewIds);
				IWorkbenchPage wp = (IWorkbenchPage) PlatformUI.getWorkbench()
					.getActiveWorkbenchWindow().getActivePage();
				wp.savePerspectiveAs(createdPd);
				
			} else {
				createdPd = perspectiveImportService.importPerspective(path, null, true);
				
			}
			
			if (createdPd != null) {
				MessageDialog.openInformation(UiDesk.getDisplay().getActiveShell(), "Import",
					"Die Perspektive '" + createdPd.getLabel()
						+ "' wurde erfolgreich importiert.");
			}
		}
	} catch (Exception e) {
		MessageDialog.openError(UiDesk.getDisplay().getActiveShell(), "Import",
			"Diese Perspektive kann nicht importiert werden.");
		LoggerFactory.getLogger(PerspektiveExportHandler.class).error("import error", e);
	}
	
	return null;
}
 
Example 18
Source File: InsertImageTool.java    From ermaster-b with Apache License 2.0 3 votes vote down vote up
private String getLoadFilePath() {

			FileDialog fileDialog = new FileDialog(PlatformUI.getWorkbench()
					.getActiveWorkbenchWindow().getShell(), SWT.OPEN);

			String[] filterExtensions = { "*.bmp;*.jpg;*.jpeg;*.gif;*.png;*.tif;*.tiff" };

			fileDialog.setFilterExtensions(filterExtensions);

			return fileDialog.open();
		}
 
Example 19
Source File: InsertImageTool.java    From ermasterr with Apache License 2.0 3 votes vote down vote up
private String getLoadFilePath() {
    final FileDialog fileDialog = new FileDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.OPEN);

    final String[] filterExtensions = {"*.bmp;*.jpg;*.jpeg;*.gif;*.png;*.tif;*.tiff"};

    fileDialog.setFilterExtensions(filterExtensions);

    return fileDialog.open();
}
 
Example 20
Source File: CompositeBrowseForFile.java    From CogniCrypt with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Open the directorDialog for the custom library, and return the path.
 *
 * @param stringOnDirectoryDialog
 * @return the selected path.
 */
private String openDirectoryDialog(final String stringOnDirectoryDialog) {
	final DirectoryDialog directoryDialog = new DirectoryDialog(getShell(), SWT.OPEN);
	directoryDialog.setText(stringOnDirectoryDialog);
	return directoryDialog.open();
}