| //------------------------------------------------------------------------------ |
| // Copyright (c) 2005, 2006 IBM Corporation and others. |
| // 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: |
| // IBM Corporation - initial implementation |
| //------------------------------------------------------------------------------ |
| package org.eclipse.epf.authoring.ui.dialogs; |
| |
| import java.io.File; |
| |
| import org.eclipse.epf.authoring.ui.AuthoringUIResources; |
| import org.eclipse.jface.dialogs.Dialog; |
| import org.eclipse.jface.dialogs.IDialogConstants; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.events.ModifyEvent; |
| import org.eclipse.swt.events.ModifyListener; |
| import org.eclipse.swt.layout.GridData; |
| import org.eclipse.swt.layout.GridLayout; |
| import org.eclipse.swt.widgets.Button; |
| 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.Text; |
| |
| /** |
| * Opens dialog to attach ctrl_filepaths |
| * |
| * @author Shashidhar Kannoori |
| * @since 1.0 |
| */ |
| public class RenameFileConflictDialog extends Dialog { |
| |
| /** |
| * The OK button. |
| */ |
| protected Button okButton; |
| |
| /** |
| * The Cancel button. |
| */ |
| protected Button cancelButton; |
| |
| /** |
| * The overwrite button |
| */ |
| protected Button overWriteButton; |
| /** |
| * @param parent |
| */ |
| |
| private Text ctrl_fileName; |
| |
| private int OVER_WRITE_ID = 22; |
| private String messageStr; |
| private String fileName; |
| |
| private Label ctrl_destination; |
| private String destination; |
| /** |
| * Creates an instance |
| * @param parent |
| */ |
| public RenameFileConflictDialog(Shell parent) { |
| super(parent); |
| } |
| |
| /** |
| * @see Dialog#createDialogArea(Composite parent) |
| */ |
| protected Control createDialogArea(Composite parent) { |
| |
| Composite dialogArea = (Composite) super.createDialogArea(parent); |
| GridLayout layout = (GridLayout) dialogArea.getLayout(); |
| layout.marginWidth = 10; |
| layout.marginHeight = 10; |
| layout.numColumns = 2; |
| GridData gridData = (GridData) dialogArea.getLayoutData(); |
| gridData.verticalIndent = 10; |
| //layout.numColumns = 3; |
| |
| // Create message area. |
| Label message = new Label(dialogArea, SWT.WRAP); |
| if(messageStr != null){ |
| message.setText(messageStr); |
| } |
| GridData data1 = new GridData(GridData.FILL_HORIZONTAL); |
| data1.horizontalSpan = 3; |
| message.setLayoutData(data1); |
| |
| |
| Label destinationLabel = new Label(dialogArea, SWT.NONE); |
| destinationLabel.setText(AuthoringUIResources.DescriptionFormPage_iconSection_fileName_destination); |
| ctrl_destination = new Label(dialogArea, SWT.NONE); |
| if(destination != null){ |
| ctrl_destination.setText(destination); |
| } |
| |
| //Create label area. |
| Label urlLabel = new Label(dialogArea, SWT.NONE); |
| urlLabel.setText(AuthoringUIResources.DescriptionFormPage_iconSection_fileName_saveAs); //$NON-NLS-1$ |
| ctrl_fileName = new Text(dialogArea, SWT.BORDER); |
| gridData.widthHint = 400; |
| gridData.verticalAlignment= GridData.VERTICAL_ALIGN_CENTER; |
| ctrl_fileName.setLayoutData(gridData); |
| if(fileName != null){ |
| ctrl_fileName.setText(fileName); |
| } |
| ctrl_fileName.addModifyListener(new ModifyListener() { |
| public void modifyText(ModifyEvent e) { |
| if (okButton != null) { |
| okButton |
| .setEnabled(ctrl_fileName.getText().trim().length() > 0); |
| } |
| fileName = ctrl_fileName.getText(); |
| File file = new File(destination+File.separator+fileName); |
| if(file.exists()){ |
| okButton.setEnabled(false); |
| overWriteButton.setEnabled(true); |
| }else{ |
| okButton.setEnabled(true); |
| overWriteButton.setEnabled(false); |
| } |
| } |
| }); |
| |
| // Button browseButton = new Button(dialogArea, SWT.NONE); |
| // browseButton.setText(AuthoringUIText.BROWSE_BUTTON_TEXT); |
| // browseButton.addSelectionListener(new SelectionListener() { |
| // public void widgetSelected(SelectionEvent event) { |
| // FileDialog dialog = new FileDialog(Display.getCurrent() |
| // .getActiveShell(), SWT.OPEN); |
| // String imageFile = dialog.open(); |
| // if (imageFile != null && imageFile.length() > 0) { |
| // File file = new File(imageFile); |
| // try { |
| // String url = file.toURL().toExternalForm(); |
| // ctrl_filepath.setText(url); |
| // } catch (Exception e) { |
| // } |
| // } |
| // } |
| // |
| // public void widgetDefaultSelected(SelectionEvent e) { |
| // } |
| // }); |
| |
| super |
| .getShell() |
| .setText( |
| AuthoringUIResources.DescriptionFormPage_iconSection_fileNameConflict_title); //$NON-NLS-1$ |
| |
| return dialogArea; |
| |
| } |
| |
| /** |
| * Creates the dialog buttons. |
| */ |
| protected void createButtonsForButtonBar(Composite parent) { |
| // Create the OK button. |
| createButton(parent, OVER_WRITE_ID, |
| AuthoringUIResources.DescriptionFormPage_iconSection_fileName_overWrite, true); |
| |
| createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, |
| true); |
| |
| // Create the Cancel button. |
| createButton(parent, IDialogConstants.CANCEL_ID, |
| IDialogConstants.CANCEL_LABEL, false); |
| |
| // Set help context for the OK button. |
| okButton = super.getButton(IDialogConstants.OK_ID); |
| |
| // Set help context for the Cancel button. |
| cancelButton = super.getButton(IDialogConstants.CANCEL_ID); |
| |
| //Set help context for the overwrite button |
| overWriteButton = super.getButton(OVER_WRITE_ID); |
| |
| okButton.setEnabled(false); |
| } |
| |
| /** |
| * Called when the OK button is selected. |
| */ |
| protected void okPressed() { |
| super.okPressed(); |
| } |
| |
| /** |
| * Returns the File Name |
| */ |
| public String getFilePath() { |
| return fileName; |
| } |
| |
| public void setFilePath(String fileName){ |
| this.fileName=fileName; |
| } |
| |
| @Override |
| protected Control createButtonBar(Composite parent) { |
| return super.createButtonBar(parent); |
| } |
| @Override |
| protected void buttonPressed(int buttonId) { |
| if(buttonId == OVER_WRITE_ID){ |
| overWritePressed(); |
| } |
| super.buttonPressed(buttonId); |
| } |
| |
| private void overWritePressed() { |
| setReturnCode(OVER_WRITE_ID); |
| close(); |
| } |
| @Override |
| protected void cancelPressed() { |
| fileName = null; |
| super.cancelPressed(); |
| } |
| |
| public String getMessageStr() { |
| return messageStr; |
| } |
| |
| public void setMessageStr(String messageStr) { |
| this.messageStr = messageStr; |
| } |
| public void setDestiation(String destination){ |
| this.destination = destination; |
| } |
| } |