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

The following examples show how to use org.eclipse.swt.SWT#OPEN . These examples are extracted from open source projects. 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
/**
 * 选择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 2
Source Project: hadoop-gpu   File: DFSActionImpl.java    License: 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
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 Project: jReto   File: SimpleChatUI.java    License: 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 5
Source Project: http4e   File: ParamsAttachManager.java    License: 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 6
Source Project: Universal-FE-Randomizer   File: OpenFileFlow.java    License: 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 7
/**
 * 选择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 8
Source Project: nebula   File: PTFileEditor.java    License: 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 9
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 10
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 11
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 12
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 13
Source Project: http4e   File: AttachManager.java    License: 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 14
Source Project: olca-app   File: FileChooser.java    License: 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 15
@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 16
Source Project: depan   File: NewGraphMLOptionPart.java    License: 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 Project: birt   File: OpenFileAction.java    License: 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 18
Source Project: ermasterr   File: InsertImageTool.java    License: 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 19
Source Project: ermaster-b   File: InsertImageTool.java    License: 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 20
/**
 * 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();
}