Package de.innovationgate.eclipse.wgadesigner.dialogs

Source Code of de.innovationgate.eclipse.wgadesigner.dialogs.ChangeDirlinkTargetDialog$NameSorter

/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*     Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.wgadesigner.dialogs;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.dialogs.SelectionStatusDialog;
import org.eclipse.ui.model.WorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchLabelProvider;

import de.innovationgate.eclipse.utils.wga.WGADesignStructureHelper;
import de.innovationgate.eclipse.wgadesigner.WGADesignerPlugin;
import de.innovationgate.eclipse.wgadesigner.editors.helpers.WGADesignViewerFilter;

public class ChangeDirlinkTargetDialog extends SelectionStatusDialog {

  private TreeViewer _treeViewer;
  private IFolder _selectedFolder;
  private IContainer _target;

  class NameSorter extends ViewerSorter {
    public int compare(Viewer viewer, Object e1, Object e2) {
      if (e1 instanceof IContainer && e2 instanceof IContainer) {
        IContainer ct1 = (IContainer) e1;
        IContainer ct2 = (IContainer) e2;
        return ct1.getName().toLowerCase().compareTo(ct2.getName().toLowerCase());
      }
      return 0;

    }
  }

  public ChangeDirlinkTargetDialog(Shell parent, IFolder selection) {
    super(parent);
    _selectedFolder = selection;
    setHelpAvailable(false);
    setTitle("Select an external Design");

  }

  protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    composite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    GridLayout layout = new GridLayout(3, false);
    composite.setLayout(layout);

    Label messageLabel = createMessageArea(composite);
    _treeViewer = createTreeViewer(composite);
    GridData gridDataLabel = new GridData(GridData.FILL_HORIZONTAL);
    gridDataLabel.horizontalSpan = 3;

    messageLabel.setLayoutData(gridDataLabel);
    GridData gridDataTree = new GridData(GridData.FILL_BOTH);
    gridDataTree.horizontalSpan = 3;
    gridDataTree.widthHint = convertWidthInCharsToPixels(80);
    gridDataTree.heightHint = convertHeightInCharsToPixels(20);
    Tree treeWidget = _treeViewer.getTree();
    treeWidget.setLayoutData(gridDataTree);

    return composite;
  }

  protected TreeViewer createTreeViewer(Composite parent) {
    int style = SWT.BORDER | (false ? SWT.MULTI : SWT.SINGLE);

    TreeViewer tableViewer = new TreeViewer(new Tree(parent, style));
    tableViewer.setContentProvider(new WorkbenchContentProvider());
    tableViewer.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider());
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
      public void selectionChanged(SelectionChangedEvent event) {
        updateOKStatus();
      }
    });

    tableViewer.setComparator(new NameSorter());
    tableViewer.addFilter((ViewerFilter) new WGADesignViewerFilter(null));
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    tableViewer.setInput(workspaceRoot);
    return tableViewer;
  }

  protected void computeResult() {   
     WGADesignStructureHelper.changeDirLink(_selectedFolder, _target);
  }

  protected void updateOKStatus() {
    updateStatus(new Status(Status.ERROR, WGADesignerPlugin.PLUGIN_ID, "Please select a Design or Plugin"));
    if (_treeViewer.getTree().getSelection().length>0 && _treeViewer.getTree().getSelection()[0] != null) {
      IContainer treeSelection = (IContainer) _treeViewer.getTree().getSelection()[0].getData();
      if (WGADesignStructureHelper.isDesignFolder(treeSelection)) {
        _target = treeSelection;
        updateStatus(new Status(Status.OK, WGADesignerPlugin.PLUGIN_ID, ""));
      }
    }
  }

}
TOP

Related Classes of de.innovationgate.eclipse.wgadesigner.dialogs.ChangeDirlinkTargetDialog$NameSorter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.