Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8279589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:23:21+00:00 2026-06-08T09:23:21+00:00

I am making an application which contains 2 views. The first one contains a

  • 0

I am making an application which contains 2 views. The first one contains a tree viewer which displays the folders from my system and the second one contains a table viewer which displays the content of a directory selected in the first view. Long story short: a file explorer.

    //initialization of the table viewer
    tableViewer = new TableViewer(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);       
    tableViewer.setContentProvider(new FileTableContentProvider());
    tableViewer.setLabelProvider(new FileTableLabelProvider());     

    //from within the implementation of any view or editor
    /*
     * getSite() - Returns the site for this workbench part (a workbench part can be a view (IViewPart) or an editor (IEditorPart))
     * this view is a selection provider; the view sends the event to all the views registered to the selection service
     */
    getSite().setSelectionProvider(tableViewer);

    //the table column "Name" is added to the table viewer
    TableColumn columnName = new TableColumn(tableViewer.getTable(), SWT.LEFT);
    columnName.setText("Name");
    columnName.setResizable(true);
    columnName.setWidth(200);

    //the table column "Date modified" is added to the table viewer
    TableColumn columnDateModified = new TableColumn(tableViewer.getTable(), SWT.LEFT);
    columnDateModified.setText("Date modified");
    columnDateModified.setResizable(true);
    columnDateModified.setWidth(200);

    //the table column "Type" is added to the table viewer
    TableColumn columnType = new TableColumn(tableViewer.getTable(), SWT.LEFT);
    columnType.setText("Type");
    columnType.setResizable(true);
    columnType.setWidth(200);       

    //make the header of the table visible
    tableViewer.getTable().setHeaderVisible(true);      

    /*
     * getSite().getPage() - gets the active workbench page.
     */
    getSite().getPage().addSelectionListener("com.awebofcode.fileexplorer.view.filetree",(ISelectionListener)this);

    /*
     * add a doubleClickListener for:
     * 1) if the object selected is a file, then the file will be opened with the associated program
     * 2) if the object selected is a directory, then enter the folder and update the tree viewer
     */
    tableViewer.addDoubleClickListener(new IDoubleClickListener(){

        @Override
        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            File itemSelected = (File) selection.getFirstElement();

            //if the selected item is a file a double click will launch the associated program
            if (itemSelected.isFile() && itemSelected.exists()){
                Program.launch(itemSelected.getAbsolutePath());
            }else if (itemSelected.isDirectory()){
                /*
                 * Update the tree viewer;
                 * PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(FileTreeView.ID) --> returns the view with the specified ID
                 * setSelection() will send an event and the setSelectionChanged will run
                 */
                ((FileTreeView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(FileTreeView.ID)).getTreeViewer().setSelection(selection);
            }
        }

    });

    //create the cell editor
    CellEditor[] editors = new CellEditor[1];
    editors[0] = new TextCellEditor(tableViewer.getTable());
    tableViewer.setColumnProperties(new String[]{"Name", "Date modified", "Type"});
    //assign the cell editors to the table viewer
    tableViewer.setCellEditors(editors);
    //set the cell modifier to the table viewer
    tableViewer.setCellModifier(new NameCellModifier(tableViewer));

I created an action that will rename the selected file or folder from the second view.

When I click on the name of the file I don’t want to enter in the editing mode.I want to stay in the selection mode and only after I click File -> Rename (action rename) the editing mode has to be enabled.

The problem is that I cannot find how to enable/disable the TextCellEditor.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:23:22+00:00Added an answer on June 8, 2026 at 9:23 am

    I didn’t find a clean solution. I will explain you what I have done so far. I have modified the code that I have posted. I use TableViewerColumn instead of TableColumn.

    Class FileTableView:

    public class FileTableView extends ViewPart implements ISelectionListener{
    
        private TableViewer tableViewer;
        private boolean cellEditable = false;
        private FirstColumnEditingSupport obj;
    
        public FileTableView() {
            super();
        }
    
        @Override
        public void createPartControl(Composite parent) {
            //initialization of the table viewer
            tableViewer = new TableViewer(parent, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.MULTI);  //SWT.MULTI - for multiple selection; SWT.FULL_SELECTION - for selection of an entire row   
            tableViewer.setContentProvider(new FileTableContentProvider());
            //it is not necessary to add a label provider for the table viewer because we will set a label provider for every column of the table
            //tableViewer.setLabelProvider(new FileTableLabelProvider());   
    
            //extract the table widget of the table viewer
            final Table table = tableViewer.getTable();
            //make the header of the table visible
            table.setHeaderVisible(true);
            //hide the lines of the table
            table.setLinesVisible(false);
    
            //create the columns of the table
            createColumns(parent, tableViewer);
    
            //set the sorter to the table viewer
            tableComparator = new TableViewerComparator();
            tableViewer.setComparator(tableComparator);
    
            //from within the implementation of any view or editor
            /*
             * getSite() - Returns the site for this workbench part (a workbench part can be a view (IViewPart) or an editor (IEditorPart))
             * this view is a selection provider; the view sends the event to all the views registered to the selection service
             */
            getSite().setSelectionProvider(tableViewer);        
    
    
            tableViewer.addSelectionChangedListener(new ISelectionChangedListener(){
                public void selectionChanged(SelectionChangedEvent event){
                    setCellEditable(false);
                }
            }); 
    
    
    
        }
    
        /*
         * method used to update the viewer from outside
         */
        public void refresh(){
            tableViewer.refresh();
        }
    
        @Override
        public void setFocus() {
            tableViewer.getControl().setFocus();
        }
    
    
    
        //method that returns the table viewer
        public TableViewer getTableViewer(){
            return tableViewer;
        }
    
    
        /*
         * get the value of the cellEditable
         */
        public boolean getCellEditable(){
            return cellEditable;
        }
    
        /*
         * set the value of the cellEditable
         */
        public void setCellEditable(boolean cellEditable){
            this.cellEditable = cellEditable;
        }
    
        public FirstColumnEditingSupport getEditingSupport(){
            return obj;
        }
    
        /*
         * method that creates columns of the table
         */
        private void createColumns(final Composite parent, final TableViewer viewer){
            String[] titles = {"Name", "Date Modified", "Size"};
            int[] width = {200, 200, 200};
    
            //first column is for the name of the file
            TableViewerColumn col = createTableViewerColumn(titles[0], width[0], 0);
            col.setLabelProvider(new ColumnLabelProvider(){
                public String getText(Object element){
                    return ((File) element).getName();
                }
    
                public Image getImage(Object element){
                    return getFirsColumnImage((File) element);
                }
            });
            obj = new FirstColumnEditingSupport(tableViewer,this);
            col.setEditingSupport(obj);
    
            //second column is for the last date modified
            col = createTableViewerColumn(titles[1], width[1], 1);
            col.setLabelProvider(new ColumnLabelProvider(){
                public String getText(Object element){
                    return formatLastModifiedDate((File) element);
                }
            });
    
            //third column is for size
            col = createTableViewerColumn(titles[2], width[2], 2);
            col.setLabelProvider(new ColumnLabelProvider(){
                public String getText(Object element){
                    return formatLength((File) element);
                }
            });
        }
    
        private TableViewerColumn createTableViewerColumn(String title, int width, final int columnNumber){
            final TableViewerColumn viewerColumn = new TableViewerColumn(tableViewer, SWT.NONE);
            final TableColumn column = viewerColumn.getColumn();
            column.setText(title);
            column.setWidth(width);
            column.setResizable(true);
            column.setMoveable(false);
            column.addSelectionListener(getSelectionAdapter(column, columnNumber));
            return viewerColumn;
        }
    
        private SelectionAdapter getSelectionAdapter(final TableColumn column, final int index){
            SelectionAdapter selectionAdapter = new SelectionAdapter(){
                public void widgetSelected(SelectionEvent e){
                    tableComparator.setColumn(index);
                    int direction = tableComparator.getDirection();
                    tableViewer.getTable().setSortDirection(direction);
                    tableViewer.getTable().setSortColumn(column);
                    tableViewer.refresh();
                }
            };
    
            return selectionAdapter;
        }
    
        /*
         * method used to return the last modified date in "dd-MM-yyyy hh:mm:ss" format
         */
        private String formatLastModifiedDate(File file){
            Date d = new Date(file.lastModified());
            SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
            return sdf.format(d);
        }
    
        /*
         * method used to return the length of the file in KB
         */
        private String formatLength(File file){
            long size = file.length()/1024;
            NumberFormat f = new DecimalFormat("#,###,### KB");
    
            return f.format(size);
        }
    
    }
    

    FirstColumnEditingSupport.java file:

    /*
     * The EditingSupport implementation defines how the content can be changed.
     */
    public class FirstColumnEditingSupport extends EditingSupport {
    
        private TableViewer tableViewer;
        private FileTableView view;
        private TextCellEditor textEditor;
    
        public FirstColumnEditingSupport(TableViewer viewer, FileTableView view) {
            super(viewer);
            this.tableViewer = viewer;
            this.view = view;
            textEditor = new TextCellEditor(tableViewer.getTable());
        }
    
        @Override
        /*
         * (non-Javadoc)
         * @see org.eclipse.jface.viewers.EditingSupport#getCellEditor(java.lang.Object)
         * EditingSupport returns in his getCellEditor() method an object of type CellEditor. This object creates the controls to change the data.
         */
        protected CellEditor getCellEditor(Object element) {
            return textEditor;
        }
    
        @Override
        /*
         * (non-Javadoc)
         * @see org.eclipse.jface.viewers.EditingSupport#canEdit(java.lang.Object)
         * The canEdit() method defines, if the cell can be edited.
         */
        protected boolean canEdit(Object element) {
            return view.getCellEditable();
        }
    
        @Override
        /*
         * (non-Javadoc)
         * @see org.eclipse.jface.viewers.EditingSupport#getValue(java.lang.Object)
         * The getValue() method receives the current object and returns the value which should be displayed.
         */
        protected Object getValue(Object element) {
            return ((File) element).getName();
        }
    
        @Override
        /*
         * (non-Javadoc)
         * @see org.eclipse.jface.viewers.EditingSupport#setValue(java.lang.Object, java.lang.Object)
         * The method setValue() in EditingSupport receives the changed value based on the user input. In this method you assign the value to your data object.
         */
        protected void setValue(Object element, Object value) {
            //value is the user input
            File oldFile = (File) element;
    
            //String path = oldFile.getAbsolutePath().substring(oldFile.getAbsolutePath().lastIndexOf(File.pathSeparatorChar));
            //System.out.println(oldFile.getParent());
            oldFile.renameTo(new File(oldFile.getParent() + "\\" + (String) value));
            tableViewer.refresh();
        }
    
        public TextCellEditor getTextCellEditor(){
            return textEditor;
        }
    
    }
    

    My RenameAction file:

    public class RenameAction extends Action implements ISelectionListener, ActionFactory.IWorkbenchAction {
    
        private final IWorkbenchWindow window;
        private IStructuredSelection itemSelected;
    
        public final static String ID = PlatformUI.PLUGIN_ID + ".RenameAction";
    
        public RenameAction(IWorkbenchWindow window){
            this.window = window;
            setId(ID);
            setText("&Rename");
            setToolTipText("Rename the file or directory selected");
            window.getSelectionService().addSelectionListener(this);
        }
        @Override
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
            if(selection.isEmpty() || !(selection instanceof IStructuredSelection)){
                return;         
            }else {
                itemSelected = (IStructuredSelection)selection;
            }
        }
    
        public void dispose(){
            window.getSelectionService().removeSelectionListener(this);
        }
    
        public void run(){
            Object firstElement = itemSelected.getFirstElement();
    
            File item = (File) firstElement;    
    
            if(item != null){
                FileTableView myTreeView= (FileTableView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(FileTableView.ID);
                myTreeView.setCellEditable(true);
            }
    
        }
    
    }
    

    My idea was:

    • by default: the cell editor of the first column is disabled
    • when the rename action is triggered (press the menu button), the cell editor of the column is enabled (myTreeView.setCellEditable(true))
    • the table line selected is in editing mode and you can change the name of the file. This part is not working quite well, because after you press the rename menu button, you can’t see that the editing mode is enabled. After you click on the table line, the editing mode is activated. Also, the editing mode is enabled for all the table lines and I wanted to be enabled only for the selected one. For this problem I haven’t got a solution.
    • after you finish typing the new name of the file, and change the selection (click on a different table line), the editing mode is disabled:

      tableViewer.addSelectionChangedListener(new ISelectionChangedListener(){
              public void selectionChanged(SelectionChangedEvent event){
                  setCellEditable(false);
              }
          });
      

    I hope my solution can help you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I'm making my first Android application, which basically contains ~250 .txt files in
I am making one Application which contains e-books in ePUB format..Problem is my original
I making one application which contains 2 input box and one input button.My qestion
I'm making an application which uses MANY images. The application gets the images from
I am developing an application which displays multiple views as tables (for example customers,
I am making a application which will show data in table view. I am
I am making an application in which I have to store data from remote
I plan on making a main menu for my application which contains 9 square
I have an Oracle table which contains event log messages for an application. We
I am making an application which makes use of context menus and has selection.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.