Search in sources :

Example 46 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project translationstudio8 by heartsome.

the class ProjectSettingTMPage method createContents.

/**
	 * Create contents of the preference page.
	 * @param parent
	 */
@Override
public Control createContents(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    container.setLayout(new GridLayout(1, false));
    tableViewer = new TableViewer(container, SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE);
    Table table = tableViewer.getTable();
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    tableViewer.setContentProvider(new ArrayContentProvider());
    createColumn(tableViewer);
    tableViewer.setInput(curDbList);
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
            DatabaseModelBean dbModel = (DatabaseModelBean) selection.getFirstElement();
            if (null == dbModel) {
                return;
            }
            if (Constants.DBTYPE_SQLITE.equals(dbModel.getDbType())) {
                String path = dbModel.getItlDBLocation() + File.separator + dbModel.getDbName();
                File file = new File(path);
                if (!file.exists()) {
                    setMessage(Messages.getString("projectsetting.ProjectSettingTMPage.FileNotFound"));
                    return;
                } else {
                    setMessage(Messages.getString("projectsetting.ProjectSettingTMPage.title"));
                }
            }
            if (dbModel != null && !dbModel.isHasMatch()) {
                setMessage(Messages.getString("projectsetting.ProjectSettingTMPage.msg1"));
            }
        }
    });
    Composite composite = new Composite(container, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    composite.setLayout(new GridLayout(5, false));
    new Label(composite, SWT.NONE);
    HSDropDownButton addBtn = new HSDropDownButton(composite, SWT.NONE);
    addBtn.setText(Messages.getString("projectsetting.ProjectSettingTMPage.addBtn"));
    Menu addMenu = addBtn.getMenu();
    MenuItem item = new MenuItem(addMenu, SWT.PUSH);
    item.setText(Messages.getString("tm.dialog.addTm.DropDownButton.AddFileTm"));
    item.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            FileDialog fileDialg = new FileDialog(getShell());
            fileDialg.setFilterExtensions(new String[] { "*.hstm", "*.*" });
            String result = fileDialg.open();
            if (result == null) {
                return;
            }
            File f = new File(result);
            if (!f.exists()) {
                return;
            }
            Map<DatabaseModelBean, String> r = null;
            try {
                r = Utils.convertFile2TmModel(f, false);
            } catch (Exception e1) {
                MessageDialog.openError(getShell(), Messages.getString("tm.dialog.addFileTm.errorTitle"), e1.getMessage());
            }
            if (r == null) {
                return;
            }
            Iterator<DatabaseModelBean> it = r.keySet().iterator();
            if (it.hasNext()) {
                DatabaseModelBean selectedVal = it.next();
                List<DatabaseModelBean> dbList = new ArrayList<DatabaseModelBean>();
                dbList.add(selectedVal);
                addToCurrDbList(dbList);
            }
        }
    });
    MenuItem serverItem = new MenuItem(addMenu, SWT.PUSH);
    serverItem.setText(Messages.getString("tm.dialog.addTm.DropDownButton.AddServerTm"));
    serverItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            TmDbManagerDialog dialog = new TmDbManagerDialog(getShell());
            dialog.setDialogUseFor(TmDbManagerDialog.TYPE_DBSELECTED);
            if (dialog.open() == Window.OK) {
                Iterator<DatabaseModelBean> it = dialog.getHasSelectedDatabase().keySet().iterator();
                List<DatabaseModelBean> dbList = new ArrayList<DatabaseModelBean>();
                while (it.hasNext()) {
                    dbList.add(it.next());
                }
                addToCurrDbList(dbList);
            }
        }
    });
    Button createBtn = new Button(composite, SWT.NONE);
    createBtn.setText(Messages.getString("projectsetting.ProjectSettingTMPage.createBtn"));
    createBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            NewTmDbWizard wizard = new NewTmDbWizard();
            ImportTmxWizardDialog dlg = new ImportTmxWizardDialog(getShell(), wizard);
            if (dlg.open() == 0) {
                DatabaseModelBean dbModel = wizard.getCreateDb();
                List<DatabaseModelBean> dbList = new ArrayList<DatabaseModelBean>();
                dbList.add(dbModel);
                addToCurrDbList(dbList);
            }
        }
    });
    Button removeBtn = new Button(composite, SWT.NONE);
    removeBtn.setText(Messages.getString("projectsetting.ProjectSettingTMPage.removeBtn"));
    removeBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            removeForCurrDbList((IStructuredSelection) tableViewer.getSelection());
        }
    });
    Button importTmxBtn = new Button(composite, SWT.NONE);
    importTmxBtn.setText(Messages.getString("projectsetting.ProjectSettingTMPage.importTmxBtn"));
    importTmxBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
            Iterator<?> it = selection.iterator();
            if (it.hasNext()) {
                DatabaseModelBean dbModel = (DatabaseModelBean) it.next();
                ImportTmxWizard wizard = new ImportTmxWizard(dbModel);
                ImportTmxWizardDialog dlg = new ImportTmxWizardDialog(getShell(), wizard);
                if (dlg.open() == 0) {
                    checkDbHashMatch(dbModel);
                    tableViewer.refresh();
                }
                // 刷新项目
                ResourceUtils.refreshCurentSelectProject();
            } else {
                MessageDialog.openInformation(getShell(), Messages.getString("projectsetting.ProjectSettingTMPage.msgTitle"), Messages.getString("projectsetting.ProjectSettingTMPage.msg2"));
            }
        }
    });
    addBtn.setFocus();
    Point addPoint = addBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point createPoint = createBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point remPoint = removeBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point importPoint = importTmxBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    int width = Math.max(importPoint.x, Math.max(remPoint.x, Math.max(addPoint.x, createPoint.x)));
    GridData btnData = new GridData();
    btnData.widthHint = width + 10;
    addBtn.setLayoutData(btnData);
    createBtn.setLayoutData(btnData);
    removeBtn.setLayoutData(btnData);
    importTmxBtn.setLayoutData(btnData);
    return container;
}
Also used : DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ImportTmxWizard(net.heartsome.cat.database.ui.tm.wizard.ImportTmxWizard) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) HSDropDownButton(net.heartsome.cat.common.ui.HSDropDownButton) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) Menu(org.eclipse.swt.widgets.Menu) HSDropDownButton(net.heartsome.cat.common.ui.HSDropDownButton) Table(org.eclipse.swt.widgets.Table) TmDbManagerDialog(net.heartsome.cat.database.ui.tm.dialog.TmDbManagerDialog) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point) SQLException(java.sql.SQLException) Point(org.eclipse.swt.graphics.Point) NewTmDbWizard(net.heartsome.cat.database.ui.tm.wizard.NewTmDbWizard) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ImportTmxWizardDialog(net.heartsome.cat.database.ui.tm.wizard.ImportTmxWizardDialog) TableViewer(org.eclipse.jface.viewers.TableViewer) File(java.io.File) FileDialog(org.eclipse.swt.widgets.FileDialog) Map(java.util.Map)

Example 47 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project translationstudio8 by heartsome.

the class XLIFFEditorImplWithNatTable method performSaveAs.

/**
	 * 执行另存为
	 * @param progressMonitor
	 *            进度条;
	 */
private void performSaveAs(IProgressMonitor progressMonitor) {
    Shell shell = getSite().getShell();
    final IEditorInput input = getEditorInput();
    // 新的EditorInput
    final IEditorInput newInput;
    // 原始的file
    final File oldFile;
    // if (input instanceof IURIEditorInput && !(input instanceof IFileEditorInput)) { // 外部文件
    FileDialog dialog = new FileDialog(shell, SWT.SAVE);
    URI uri = ((IURIEditorInput) input).getURI();
    IPath oldPath = URIUtil.toPath(uri);
    if (oldPath != null) {
        dialog.setFileName(oldPath.lastSegment());
        // 设置所在文件夹
        dialog.setFilterPath(oldPath.removeLastSegments(1).toOSString());
        oldFile = oldPath.toFile();
    } else {
        oldFile = new File(uri);
    }
    // 得到保存路径
    String newPath = dialog.open();
    if (newPath == null) {
        if (progressMonitor != null)
            progressMonitor.setCanceled(true);
        return;
    }
    // 检查文件是否存在,如果存在则确认是否覆盖
    final File localFile = new File(newPath);
    if (localFile.exists()) {
        String msg = MessageFormat.format(Messages.getString("editor.XLIFFEditorImplWithNatTable.msg1"), newPath);
        MessageDialog overwriteDialog = new MessageDialog(shell, Messages.getString("editor.XLIFFEditorImplWithNatTable.overwriteDialog"), null, msg, MessageDialog.WARNING, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1);
        if (overwriteDialog.open() != MessageDialog.OK) {
            if (progressMonitor != null) {
                progressMonitor.setCanceled(true);
                return;
            }
        }
    }
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    // 得到新文件
    IFile file = root.getFileForLocation(URIUtil.toPath(localFile.toURI()));
    if (file != null) {
        // 是“WorkSpace”内的文件
        newInput = new FileEditorInput(file);
    } else {
        // 不是“WorkSpace”内的文件
        try {
            IFileStore fileStore = EFS.getStore(localFile.toURI());
            newInput = new FileStoreEditorInput(fileStore);
        } catch (CoreException ex) {
            // EditorsPlugin.log(ex.getStatus());
            LOGGER.error("", ex);
            String title = Messages.getString("editor.XLIFFEditorImplWithNatTable.msgTitle1");
            String msg = MessageFormat.format(Messages.getString("editor.XLIFFEditorImplWithNatTable.msg2"), ex.getMessage());
            MessageDialog.openError(shell, title, msg);
            return;
        }
    }
    // } else {
    // SaveAsDialog dialog = new SaveAsDialog(shell);
    // // 源文件
    // IFile original = (input instanceof IFileEditorInput) ? ((IFileEditorInput) input).getFile() : null;
    // if (original != null) {
    // dialog.setOriginalFile(original); // 添加源文件信息
    // oldFile = original.getLocation().toFile();
    // if ((!oldFile.exists() || !oldFile.canRead()) && original != null) {
    // String message = MessageFormat.format(
    // "The original file ''{0}'' has been deleted or is not accessible.", original.getName());
    // dialog.setErrorMessage(null);
    // dialog.setMessage(message, IMessageProvider.WARNING);
    // }
    // } else {
    // oldFile = null;
    // }
    // dialog.create();
    //
    // if (dialog.open() == MessageDialog.CANCEL) { // 打开“另存为”对话框,用户点击了“取消”按钮
    // if (progressMonitor != null)
    // progressMonitor.setCanceled(true);
    // return;
    // }
    //
    // IPath filePath = dialog.getResult(); // 获得用户选择的路径
    // if (filePath == null) { // 检查路径
    // if (progressMonitor != null)
    // progressMonitor.setCanceled(true);
    // return;
    // }
    //
    // IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    // IFile file = root.getFile(filePath);
    // newInput = new FileEditorInput(file);
    // }
    saveAs(newInput, oldFile, progressMonitor);
}
Also used : IURIEditorInput(org.eclipse.ui.IURIEditorInput) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) URI(java.net.URI) Shell(org.eclipse.swt.widgets.Shell) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IFileStore(org.eclipse.core.filesystem.IFileStore) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) IFile(org.eclipse.core.resources.IFile) File(java.io.File) FileDialog(org.eclipse.swt.widgets.FileDialog) IEditorInput(org.eclipse.ui.IEditorInput) IURIEditorInput(org.eclipse.ui.IURIEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 48 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project translationstudio8 by heartsome.

the class ExportAsHtmlHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    String elementName = event.getParameter("elementName");
    IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    Shell shell = activeEditor.getEditorSite().getShell();
    if (activeEditor == null || !(activeEditor instanceof XLIFFEditorImplWithNatTable)) {
        return null;
    }
    XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) activeEditor;
    if (xliffEditor.isMultiFile()) {
        MessageDialog.openInformation(shell, "", "当前编辑器打开了多个文件,无法执行该操作。");
    }
    IEditorInput input = xliffEditor.getEditorInput();
    URI uri = null;
    if (input instanceof FileEditorInput) {
        uri = ((FileEditorInput) input).getURI();
    } else if (input instanceof FileStoreEditorInput) {
        uri = ((FileStoreEditorInput) input).getURI();
    } else {
        return null;
    }
    File xliff = new File(uri);
    FileDialog fd = new FileDialog(shell, SWT.SAVE);
    String[] names = { "HTML Files [*.html]", "All Files [*.*]" };
    //$NON-NLS-1$ //$NON-NLS-2$
    String[] extensions = { "*.html", "*.*" };
    fd.setFilterExtensions(extensions);
    fd.setFilterNames(names);
    //$NON-NLS-1$
    fd.setFileName(xliff.getName() + ".html");
    String out = fd.open();
    if (out == null) {
        return null;
    }
    XLFHandler handler = xliffEditor.getXLFHandler();
    boolean result = handler.saveAsHtml(xliff.getAbsolutePath(), out, elementName);
    if (result) {
        IWorkbenchPage page = xliffEditor.getEditorSite().getPage();
        OpenEditorUtil.OpenFileWithSystemEditor(page, out);
    } else {
        MessageDialog.openInformation(shell, "", "文件 “" + out + "” 保存失败!请重试。");
    }
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IEditorPart(org.eclipse.ui.IEditorPart) URI(java.net.URI) Shell(org.eclipse.swt.widgets.Shell) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) File(java.io.File) FileDialog(org.eclipse.swt.widgets.FileDialog) IEditorInput(org.eclipse.ui.IEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 49 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project translationstudio8 by heartsome.

the class AddOrUpdateLanguageDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite tparent = (Composite) super.createDialogArea(parent);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
    tparent.setLayoutData(data);
    GridLayout layout = new GridLayout(3, false);
    tparent.setLayout(layout);
    GridData txtData = new GridData(GridData.FILL_HORIZONTAL);
    txtData.horizontalSpan = 2;
    Label lbl = new Label(tparent, SWT.NONE);
    lbl.setText(Messages.getString("languagecode.AddOrUpdateLanguageDialog.lblLangImage"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(lbl);
    imageLabel = new Label(tparent, SWT.NONE);
    GridData imGd = new GridData();
    imGd.widthHint = 16;
    imGd.heightHint = 12;
    imageLabel.setLayoutData(imGd);
    imageLabel.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
    try {
        String bundlePath = FileLocator.toFileURL(Activator.getDefault().getBundle().getEntry("")).getPath();
        if (this.imagePath != null && !this.imagePath.equals("")) {
            String imagePath = bundlePath + this.imagePath;
            if (image != null && !image.isDisposed()) {
                image.dispose();
            }
            image = new Image(getShell().getDisplay(), imagePath);
        }
        if (image != null) {
            ImageData imgData = image.getImageData().scaledTo(16, 12);
            if (image != null && !image.isDisposed()) {
                image.dispose();
            }
            image = new Image(getShell().getDisplay(), imgData);
            imageLabel.setData(this.imagePath);
        } else {
            if (image != null && !image.isDisposed()) {
                image.dispose();
            }
            image = new Image(getShell().getDisplay(), bundlePath + ImageConstant.LANG_EMPTYPIC);
        }
        imageLabel.setImage(image);
    } catch (IOException e) {
        e.printStackTrace();
    }
    imageLabel.setToolTipText(Messages.getString("languagecode.AddOrUpdateLanguageDialog.imageLabel"));
    imageLabel.addListener(SWT.MouseUp, new Listener() {

        public void handleEvent(Event event) {
            FileDialog dlg = new FileDialog(getShell());
            dlg.setFilterExtensions(new String[] { "*.png" });
            String path = dlg.open();
            if (path != null) {
                ImageData data = new ImageData(path).scaledTo(16, 12);
                if (image != null && !image.isDisposed()) {
                    image.dispose();
                }
                image = new Image(getShell().getDisplay(), data);
                imageLabel.setImage(image);
                imageLabel.setData(path);
            }
        }
    });
    new Label(tparent, SWT.NONE).setText(Messages.getString("languagecode.AddOrUpdateLanguageDialog.lblImage"));
    lbl = new Label(tparent, SWT.NONE);
    lbl.setText(Messages.getString("languagecode.AddOrUpdateLanguageDialog.txtCode"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(lbl);
    txtCode = new Text(tparent, SWT.BORDER);
    txtCode.setLayoutData(txtData);
    txtCode.setText(strCode == null ? "" : strCode);
    lbl = new Label(tparent, SWT.NONE);
    lbl.setText(Messages.getString("languagecode.AddOrUpdateLanguageDialog.txtName"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(lbl);
    txtName = new Text(tparent, SWT.BORDER);
    txtName.setLayoutData(txtData);
    txtName.setText(strName == null ? "" : strName);
    lbl = new Label(tparent, SWT.NONE);
    lbl.setText(Messages.getString("languagecode.AddOrUpdateLanguageDialog.isBidi"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(lbl);
    btnIsBidi = new Button(tparent, SWT.RADIO);
    btnIsBidi.setText(Messages.getString("languagecode.AddOrUpdateLanguageDialog.btnIsBidi"));
    btnIsNotBidi = new Button(tparent, SWT.RADIO);
    btnIsNotBidi.setText(Messages.getString("languagecode.AddOrUpdateLanguageDialog.btnIsNotBidi"));
    if (blnIsBidi) {
        btnIsBidi.setSelection(true);
    } else {
        btnIsNotBidi.setSelection(true);
    }
    tparent.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    txtCode.forceFocus();
    txtCode.selectAll();
    return tparent;
}
Also used : Listener(org.eclipse.swt.widgets.Listener) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) IOException(java.io.IOException) Image(org.eclipse.swt.graphics.Image) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) ImageData(org.eclipse.swt.graphics.ImageData) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 50 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project translationstudio8 by heartsome.

the class NewProjectWizardSourceFilePage method createControl.

/**
	 * Create contents of the wizard.
	 * @param parent
	 */
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    container.setLayout(new GridLayout(1, false));
    setControl(container);
    fileListViewer = new ListViewer(container, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
    fileListViewer.getList().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    fileListViewer.setContentProvider(new ArrayContentProvider());
    fileListViewer.setInput(srcFileList);
    if (this.converterCaller != null) {
        final Button btnConvert = new Button(container, SWT.CHECK);
        btnConvert.setText(Messages.getString("wizard.NewProjectWizardSourceFilePage.btnConvert"));
        btnConvert.setSelection(true);
        isOpenConverter = true;
        btnConvert.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                isOpenConverter = btnConvert.getSelection();
            }
        });
    }
    Composite composite = new Composite(container, SWT.NONE);
    composite.setLayout(new GridLayout(2, false));
    composite.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false, 1, 1));
    Button addBtn = new Button(composite, SWT.NONE);
    addBtn.setText(Messages.getString("wizard.NewProjectWizardSourceFilePage.addBtn"));
    addBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            FileDialog dlg = new FileDialog(getShell(), SWT.MULTI);
            // CONVERTEREXTENTION
            String[] supExtentions = new String[] { "*.mif;*.idml;*.inx;*.xlf;*.rtf;*.po;*.properties;*.js;*.mqxlz;*.doc;*.xls;*.ppt;" + "*.docx;*.xlsx;*.pptx;*.odt;*.ods;*.odp;*.odg;*.rtf;*.sdlxliff;*.ttx;*.htm;*.html;*.txt;*.resx;*.rc;*.xml;*.txml", "*.*" };
            dlg.setFilterExtensions(supExtentions);
            if (dlg.open() != null) {
                String[] files = dlg.getFileNames();
                for (int i = 0; i < files.length; i++) {
                    StringBuffer buf = new StringBuffer(dlg.getFilterPath());
                    buf.append(File.separator);
                    buf.append(files[i]);
                    String file = buf.toString();
                    if (!srcFileList.contains(file)) {
                        srcFileList.add(file);
                    }
                }
                fileListViewer.refresh();
            }
        }
    });
    Button deleteBtn = new Button(composite, SWT.NONE);
    deleteBtn.setText(Messages.getString("wizard.NewProjectWizardSourceFilePage.deleteBtn"));
    deleteBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selections = (IStructuredSelection) fileListViewer.getSelection();
            Iterator<?> it = selections.iterator();
            while (it.hasNext()) {
                String file = (String) it.next();
                srcFileList.remove(file);
            }
            fileListViewer.refresh();
        }
    });
}
Also used : ListViewer(org.eclipse.jface.viewers.ListViewer) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Iterator(java.util.Iterator) FileDialog(org.eclipse.swt.widgets.FileDialog)

Aggregations

FileDialog (org.eclipse.swt.widgets.FileDialog)512 File (java.io.File)198 SelectionEvent (org.eclipse.swt.events.SelectionEvent)181 Button (org.eclipse.swt.widgets.Button)181 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)160 Label (org.eclipse.swt.widgets.Label)153 Text (org.eclipse.swt.widgets.Text)151 Composite (org.eclipse.swt.widgets.Composite)136 Shell (org.eclipse.swt.widgets.Shell)120 GridData (org.eclipse.swt.layout.GridData)110 ModifyListener (org.eclipse.swt.events.ModifyListener)109 ModifyEvent (org.eclipse.swt.events.ModifyEvent)107 GridLayout (org.eclipse.swt.layout.GridLayout)105 Group (org.eclipse.swt.widgets.Group)90 Event (org.eclipse.swt.widgets.Event)76 Listener (org.eclipse.swt.widgets.Listener)76 Display (org.eclipse.swt.widgets.Display)72 FormAttachment (org.eclipse.swt.layout.FormAttachment)68 FormData (org.eclipse.swt.layout.FormData)68 FormLayout (org.eclipse.swt.layout.FormLayout)68